[Numpy-discussion] matrix default to column vector?

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Jun 5 13:44:18 EDT 2009

On Fri, Jun 5, 2009 at 1:33 PM, Geoffrey Ely <gely at usc.edu> wrote:
> On Jun 5, 2009, at 10:18 AM, josef.pktd at gmail.com wrote:
>> I'm only using arrays for consistency, but my econometrics code is
>> filled with arr[np.newaxis,:] .
> arr[None,:] is a lot cleaner in my opinion, especially when using
> "numpy" as the namespace.

It took me a long time to figure out that None and np.newaxis do the
same thing. I find newaxis more descriptive and mostly stick to it.
When I started looking at numpy, I was always wondering what these
"None"s were doing in the code.

just one more useful trick to preserve dimension, using slices instead
of index avoids arr[None,:], but requires more thinking.


>>> X
matrix([[1, 0],
        [1, 1]])
>>> Y
array([[1, 0],
       [1, 1]])

>>> X[0,:].shape == Y[0:1,:].shape
>>> X[0,:] == Y[0:1,:]
matrix([[ True,  True]], dtype=bool)

> -Geoff

More information about the NumPy-Discussion mailing list