[Numpy-discussion] possible bug with numpy.object_
Charles R Harris
charlesr.harris at gmail.com
Thu Aug 31 10:33:25 CDT 2006
On 8/31/06, Fernando Perez <fperez.net at gmail.com> wrote:
> On 8/31/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> > What about
> > N.array(3).size
> > N.array().size
> > N.array([3,3]).size
> > 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
> Out: ()
> In : N.array().shape
> Out: (1,)
> In : N.array([3,3]).shape
> Out: (2,)
> In : N.array().shape
> Out: (0,)
> 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)
> /home/fperez/research/code/mjmdim/pycode/<ipython console>
> IndexError: index out of bounds
> And is this really expected?
> In : N.array().any()
> Out: False
This could be interpreted as : exists x, x element of array, s.t. x is true.
In : N.array().all()
> Out: True
Seems right: for all x, x element of array, x is true.
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?
Fun with empty sets! The question is, is a zero dimensional array an empty
container or does it contain its value. The numpy choice of treating zero
dimensional arrays as both empty containers and scalar values makes the
determination a bit ambiguous although it is consistent with the indexing
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion