[Numpy-discussion] dtype=object behavior change from 0.9.6 to beta 1
Tom Denniston
tom.denniston at alum.dartmouth.org
Thu Aug 31 14:29:15 CDT 2006
I would think one would want to throw an error when the data has
inconsistent dimensions. This is what numpy does for other dtypes:
In [10]: numpy.array(([1,2,3], [4,5,6]))
Out[10]:
array([[1, 2, 3],
[4, 5, 6]])
In [11]: numpy.array(([1,3], [4,5,6]))
---------------------------------------------------------------------------
exceptions.TypeError Traceback (most recent
call last)
TypeError: an integer is required
On 8/31/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
>
> Tom Denniston wrote:
> > So my question is what is the _advantage_ of the new semantics?
>
> what if the list don't have the same length, and therefor can not be
> made into an array, now you get a weird result:
>
> >>>N.array([N.array([1,'A',None],dtype=object),N.array
> ([2,2,'Somestring',5],dtype=object)]).shape
> ()
>
> Now you get an Object scalar.
>
> but:
> >>>N.array([N.array([1,'A',None],dtype=object),N.array
> ([2,2,'Somestring',5],dtype=object)],dtype=object).shape
> (2,)
>
> Now you get a length 2 array, just like before: far more consistent.
> With the old semantics, if you test your code with arrays of different
> lengths, you'll get one thing, but if they then happen to be the same
> length in some production use, the whole thing breaks -- this is a Bad
> Idea.
>
> Object arrays are just plain weird, there is nothing you can do that
> will satisfy every need. I think it's best for the array constructor to
> not try to guess at what the hierarchy of sequences you *meant* to use.
> You can (and probably should) always be explicit with:
>
> >>> A = N.empty((2,), dtype=object)
> >>> A
> array([None, None], dtype=object)
> >>> A[:] = [N.array([1,'A', None],
> dtype=object),N.array([2,2,'Somestring',5],dtype=object)]
> >>> A
> array([[1 A None], [2 2 Somestring 5]], dtype=object)
>
> -Chris
>
>
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> NOAA/OR&R/HAZMAT (206) 526-6959 voice
> 7600 Sand Point Way NE (206) 526-6329 fax
> Seattle, WA 98115 (206) 526-6317 main reception
>
> Chris.Barker at noaa.gov
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060831/8d9fc86f/attachment.html
More information about the Numpy-discussion
mailing list