[Numpy-discussion] Can't mix np.newaxis with boolean indexing
Sat Aug 20 02:47:10 CDT 2011
Your syntax is not as intuitive as you may think.
Suppose I take a matrix instead
a = np.array([1,2,3,4]).reshape(2,2)
b = (a>1) # np.array([[False,True],[True,True]])
How would a[b,np.newaxis] be supposed to work?
Note that other (simple) slices work perfectly with newaxis, such as
On 19 August 2011 17:50, Benjamin Root <firstname.lastname@example.org> wrote:
> I could have sworn that this use to work:
> import numpy as np
> a = np.random.random((100,))
> b = (a > 0.5)
> print a[b, np.newaxis]
> But instead, I get this error on the latest master:
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: long() argument must be a string or a number, not 'NoneType'
> Note, the simple work-around would be "a[b][:, np.newaxis]", but I can't
> imagine why the intuitive syntax would not be valid.
> Ben Root
> NumPy-Discussion mailing list
More information about the NumPy-Discussion