Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I am having problems when indexing empty numpy arrays with empty lists.

It works fine for one-dimension arrays:

>>> a = ones(0)
>>> a
array([], dtype=float64)
>>> ind = []
>>> a[ind]
array([], dtype=float64)

If I create an empty array with 3 columns, I get an error:

>>> b = ones((0, 3))
>>> b
array([], shape=(0, 3), dtype=float64)
>>> b[ind]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: invalid index

I am trying to extract no rows from an array with 0 rows and 3 columns. I would expect to get an empty 0x3 array, the same as I get when the array is not empty:

>>> c = ones((2, 3))
>>> c
array([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.]])
>>> c[ind]
array([], shape=(0, 3), dtype=float64)

Is there a reason why it doesn't work for empty 2-dimensional arrays? Is there any way to make this work in python?

share|improve this question
    
Works fine with me ... no error occuring ... have numpy version 1.8.2 – plonser Apr 10 at 8:42
    
Cant reproduce it neither with numpy 1.8.1 – lapinkoira Apr 10 at 8:45
    
I am using numpy 1.6.1. Thanks, I will update to newer version – burak1000 Apr 10 at 8:48
    
It probably relates to this issue – ali_m Apr 11 at 21:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.