A correction for the typo below.
Thanks,
Masha
--------------------
liu...@usc.edu
On Aug 10, 2009, at 12:19 PM, Maria Liukis wrote:
Hello everybody,
I'm using following versions of Scipy and Numpy packages:
>>> scipy.__version__
'0.7.1'
>>> np.__version__
'1.3.0'
My code uses boolean array to filter 2-dimensional array which
sometimes happens to be an empty array. It seems like I have to
take special care when dimension I'm filtering is zero, otherwise
I'm getting an "IndexError: invalid index" exception:
>>> import numpy as np
>>> a = np.zeros((2,10))
Sorry, copied wrong line for an example which creates an array:
>>> a = np.ones((2,10))
>>> a
array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])
>>> filter_array = np.zeros(2,)
>>> filter_array
array([False, False], dtype=bool)
>>> a[filter_array,:]
array([], shape=(0, 10), dtype=float64)
>>>>>>
Now if filtered dimension is zero:
>>> a = np.ones((0,10))
>>> a
array([], shape=(0, 10), dtype=float64)
>>> filter_array = np.zeros((0,), dtype=bool)
>>> filter_array
array([], dtype=bool)
>>> filter_array.shape
(0,)
>>> a.shape
(0, 10)
>>> a[filter_array,:]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: invalid index
>>>
Would somebody know if it's an expected behavior, a package bug or
am I doing something wrong?
Thanks in advance,
Masha
--------------------
liu...@usc.edu
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion