Hi, I posted this before on scipy-user, maybe that was the wrong place. Have a look at this: # ===================================== In [1]: import numpy In [2]: numpy.__version__ Out[2]: '0.9.7.2484' In [3]: a = numpy.array([[0, 1],[2, 3], [4, 5],[6, 7],[8, 9]]) In [4]: b = numpy.array([False, True, True, True, False]) In [5]: a[b] Out[5]: array([[2, 3], [4, 5], [6, 7]]) In [6]: a[b,:] --------------------------------------------------------------------------- exceptions.IndexError Traceback (most recent call last) /home/jloehnert/<console> IndexError: arrays used as indices must be of integer type In [7]: a[numpy.nonzero(b),:] Out[7]: array([[2, 3], [4, 5], [6, 7]]) # ====================== Is there a reason to forbid a[b, :] with boolean array b? Johannes
Johannes Loehnert wrote:
Hi,
I posted this before on scipy-user, maybe that was the wrong place.
Have a look at this:
# ===================================== In [1]: import numpy
In [2]: numpy.__version__ Out[2]: '0.9.7.2484'
In [3]: a = numpy.array([[0, 1],[2, 3], [4, 5],[6, 7],[8, 9]])
In [4]: b = numpy.array([False, True, True, True, False])
In [5]: a[b] Out[5]: array([[2, 3], [4, 5], [6, 7]])
In [6]: a[b,:] --------------------------------------------------------------------------- exceptions.IndexError Traceback (most recent call last)
/home/jloehnert/<console>
IndexError: arrays used as indices must be of integer type
In [7]: a[numpy.nonzero(b),:] Out[7]: array([[2, 3], [4, 5], [6, 7]]) # ======================
Is there a reason to forbid a[b, :] with boolean array b?
I think admitting this behavior would require even more checks in already complicated code. I'm not sure it's worth it. I don't have an principled opposition, but it's not on my list of things to implement. -Travis
participants (2)
-
Johannes Loehnert
-
Travis Oliphant