[Numpy-discussion] matrix default to column vector?
Fri Jun 5 12:44:18 CDT 2009
On Fri, Jun 5, 2009 at 1:33 PM, Geoffrey Ely <firstname.lastname@example.org> wrote:
> On Jun 5, 2009, at 10:18 AM, email@example.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[0,:].shape == Y[0:1,:].shape
>>> X[0,:] == Y[0:1,:]
matrix([[ True, True]], dtype=bool)
More information about the Numpy-discussion