[Numpy-discussion] 0-dimensional object arrays
schofield at ftw.at
Tue Jan 24 06:16:02 CST 2006
I've been attempting to use an object array to group together a
collection of different-length arrays or lists, and I'm getting
unexpected results. Here's an example:
>>> import numpy
>>> a = numpy.array([[1,2],[1,2,3]],object)
I expected here that 'a' would be an array of dimension (2,), holding
two Python lists of integers. Was I wrong to expect this? It seems
instead that 'a' is a 0-dimensional array holding one object:
array([[1, 2], [1, 2, 3]], dtype=object)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
IndexError: 0-d arrays can't be indexed.
This behaviour seems less useful. Would you agree this is a bug in the
I also can't explain this behaviour:
>>>  + a
>>> a + 
I guess I would have expected these commands to be equivalent
These results seem more sensible:
[[1, 2], [1, 2, 3]]
[[1, 2], [1, 2, 3], [1, 2], [1, 2, 3]]
although these last two commands return Python lists, without the 0-d
array wrapper, which isn't consistent with other 0-d arrays.
On the whole, 0-d object arrays seem quite strange beasts. Could
someone please enlighten me on why they deserve to exist? ;) They seem
inconsistent with the new simplified interface to object array
elements. Could we get rid of them entirely?!
More information about the Numpy-discussion