[Numpy-discussion] flat indexing of object arrays

Travis Oliphant oliphant at ee.byu.edu
Thu Oct 5 17:42:01 CDT 2006


Matthew Brett wrote:

>Hi,
>
>On 10/5/06, Martin Wiechert <martin.wiechert at gmx.de> wrote:
>  
>
>>Hi list,
>>
>>when I try to assign a sequence as an element of an object array via flat
>>indexing only the first element of the sequence is assigned:
>>    
>>
>
>I've also been having trouble with flat on object arrays.
>
>Is this intended?
>
>In [1]: from numpy import *
>
>In [2]: a = arange(2)
>
>In [3]: a[1]
>Out[3]: 1
>
>In [4]: a.flat[1]
>Out[4]: 1
>
>In [5]: b = array([a], dtype=object)
>
>In [6]: b[1]
>---------------------------------------------------------------------------
>exceptions.IndexError                                Traceback (most
>recent call last)
>
>/home/mb312/devel_trees/scipy/Lib/io/<ipython console>
>
>IndexError: index out of bounds
>
>In [7]: b.flat[1]
>Out[7]: 1
>
>  
>

This is correct behavior.  Look at the shape of b.  It is being indexed 
correctly.

The problem is that it is ambiguous as to what is wanted when you write

b = array([a], dtype=object).

We have gone through the rounds on this one and the current behavior is 
our best compromise.

-Travis







More information about the Numpy-discussion mailing list