[Numpy-discussion] mixing arrays and matrices: squeeze yes, flattened no?

Sven Schreiber svetosch at gmx.net
Tue Feb 21 15:57:00 EST 2006

Christopher Barker schrieb:

> and you can easily get a column vector out of an array, if you remember
> that you want to keep it 2-d. i.e. use a slice rather than an index:
>>>> import numpy as N
>>>> a = N.ones((5,10))
>>>> a[:,1].shape # an index: it reduces the rank
> (5,)
>>>> a[:,1:2].shape # a slice: it keeps the rank
> (5, 1)

That's very interesting, thanks. But I find it a little
unintuitive/surprising, so I'm not sure if I will use it. I fear that I
wouldn't understand my own code after a while of not working on it.

I guess I'd rather follow the advice and just remember to treat 1d as a row.
But thanks alot,

More information about the NumPy-Discussion mailing list