[Numpy-discussion] Problem with concatenate and object arrays

Travis Oliphant oliphant at ee.byu.edu
Thu Sep 7 18:15:33 EDT 2006


Charles R Harris wrote:

>
>     So is this intentional?
>
>     In [24]: a = array([[],[],[]], dtype=object)
>
>     In [25]: a.shape
>     Out[25]: (3, 0)
>
>     In [26]: a = array([], dtype=object)
>
>     In [27]: a.shape
>     Out[27]: (0,)
>      
>     One could argue that the first array should have shape (3,)
>
Yes, it's intentional because it's the old behavior of Numeric.  And it 
follows the rule that object arrays don't do anything special unless the 
old technique of using [] as 'dimension delimiters' breaks down.

>
> And this doesn't look quite right:
>
> In [38]: a = array([[1],[2],[3]], dtype=object)
>
> In [39]: a.shape
> Out[39]: (3, 1)
>
> In [40]: a = array([[1],[2,3],[4,5]], dtype=object)
>
> In [41]: a.shape
> Out[41]: (3,)
>  

Again, same reason as before.  The first example works fine to construct 
a rectangular array of object arrays of dimension 2.  The second only 
does if we limit the number of dimensions to 1.

The rule is that array needs nested lists with the same number of 
dimensions unless you have object arrays.  Then, the dimensionality will 
be determined by finding the largest number of dimensions possible for 
consistency of shape.

-Travis






More information about the NumPy-Discussion mailing list