[Numpy-discussion] dtype=object behavior change from 0.9.6 to beta 1

Charles R Harris charlesr.harris at gmail.com
Thu Aug 31 14:59:40 CDT 2006


On 8/31/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
> Tom Denniston wrote:
> > I would think one would want to throw an error when the data has
> > inconsistent dimensions.
>
> But it doesn't have inconsistent dimensions - they are perfectly
> consistent with a (2,) array of objects. How is the code to know what
> you intended?


Same as it produces a float array from array([1,2,3.0]). Array is a
complicated function for precisely these sort of reasons, but the
convenience makes it worthwhile. So, if a list contains something that can
only be interpreted as an object, dtype should be set to object.

With numeric types, it is unambiguous to march down through the
> sequences until you get a number. As a sequence is an object, there no
> way to unambiguously do this automatically.
>
> Perhaps the way to solve this is for the array constructor to take a
> "shape" or "rank" argument, so you could specify what you intend. But
> that's really just syntactic sugar to avoid for calling numpy.empty()
> first.
>
> Perhaps a numpy.object_array() constructor would be useful, although as
> I think about it, even specifying a shape or rank would not be
> unambiguous!
>
> This is a useful discussion. If we ever get a nd-array into the standard
> lib, I suspect that object arrays will get heavy use -- better to clean
> up the semantics now.
>
> Perhaps a Wiki page on building object arrays is called for.
>
> -Chris


Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060831/3150bdcc/attachment-0001.html 


More information about the Numpy-discussion mailing list