[Numpy-discussion] stumped numpy user seeks help

Bill Baxter wbaxter at gmail.com
Wed Aug 30 17:18:34 EDT 2006


On 8/30/06, Sven Schreiber <svetosch at gmx.net> wrote:
> Mathew Yeates schrieb:
> will be a numpy matrix, use <asarray> if you don't like that. But here
> it's really nice to work with matrices, because otherwise .sum() will
> give you a 1-d array sometimes, and that will suddenly look like a row
> to <hstack> (instead of a nice column vector) and wouldn't work --
> that's why matrices are so great and everybody should be using them ;-)

column_stack would work perfectly in place of hstack there if it only
didn't have the silly behavior of transposing arguments that already
are 2-d.

For reminders, here's the replacement implementation of column_stack I
proposed on July 21:

def column_stack(tup):
   def transpose_1d(array):
        if array.ndim<2: return _nx.transpose(atleast_2d(array))
        else: return array
   arrays = map(transpose_1d,map(atleast_1d,tup))
   return _nx.concatenate(arrays,1)

This was in a big ticket I submitted about overhauling r_,c_,etc,
which was largely ignored.  Maybe I should resubmit this by itself...

--bb




More information about the NumPy-Discussion mailing list