[Numpy-discussion] possible bug with numpy.object_
fperez.net at gmail.com
Thu Aug 31 10:08:36 CDT 2006
On 8/31/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> What about
> Essentially, the  is being treated as an object when you explicitly
> ask for an object array in exactly the same way as 3 is being treated as
> a number in the default case. It's just that '[' ']' is "also" being
> used as the dimension delimiter and thus the confusion.
> It is consistent. It's a corner case, and I have no problem fixing the
> special-case code running when dtype=object so that array(,
> dtype=object) returns an empty array, if that is the consensus.
I wasn't really complaining: these are corner cases I've never seen in
real use, so I'm not really sure how critical it is to worry about
them. Though I could see code which does automatic size/shape checks
tripping on some of them. The shape tuples shed a bit of light on
what's going on for the surprised (like myself):
In : N.array(3).shape
In : N.array().shape
In : N.array([3,3]).shape
In : N.array().shape
In : N.array([]).shape
Out: (1, 0)
In : N.array([,]).shape
Out: (2, 0)
I won't really vote for any changes one way or another, as far as I'm
concerned it's one of those 'learn the library' things. I do realize
that the near-ambiguity between '' as an empty object and '' as
the syntactic delimiter for a container makes this case a bit of a
I guess my only remaining question is: what is the difference between
outputs #8 and #11 above? Is an empty shape tuple == array scalar,
while a (0,) shape indicates a one-dimensional array with no elements?
If this interpretation is correct, what is the usage of the latter
kind of object, given how it can't even be indexed?
In : N.array()
exceptions.IndexError Traceback (most
recent call last)
IndexError: index out of bounds
And is this really expected?
In : N.array().any()
In : N.array().all()
It's a bit funny to have an array for which 'no elements are true'
(any==false), yet 'all are true' (all==true), isn't it?
More information about the Numpy-discussion