[Numpy-discussion] Can't mix np.newaxis with boolean indexing
Olivier Verdier
zelbier@gmail....
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
a[:1,np.newaxis]
== Olivier
On 19 August 2011 17:50, Benjamin Root <ben.root@ou.edu> 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.
>
> Thanks,
> Ben Root
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
More information about the NumPy-Discussion
mailing list