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

Tom Denniston tom.denniston at alum.dartmouth.org
Thu Aug 31 11:59:36 EDT 2006


For this simple example yes, but if one of the nice things about the array
constructors is that they know that lists, tuple and arrays are just
sequences and any combination of them is valid numpy input.  So for instance
a list of tuples yields a 2d array.  A list of tuples of 1d arrays yields a
3d array.  A list of 1d arrays yields 2d array.  This was the case
consistently across all dtypes.  Now it is the case across all of them
except for the dtype=object which has this unusual behavior.  I agree that
vstack is a better choice when you know you have a list of arrays but it is
less useful when you don't know and you can't force a type in the vstack
function so there is no longer an equivalent to the dtype=object behavior:

In [7]: numpy.array([numpy.array([1,2,3]), numpy.array([4,5,6])],
dtype=object)
Out[7]:
array([[1, 2, 3],
       [4, 5, 6]], dtype=object)

In [8]: numpy.vstack([numpy.array([1,2,3]), numpy.array([4,5,6])],
dtype=object)
---------------------------------------------------------------------------
exceptions.TypeError                                 Traceback (most recent
call last)


TypeError: vstack() got an unexpected keyword argument 'dtype'



On 8/31/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
> On 8/31/06, Tom Denniston
> <tom.denniston at alum.dartmouth.org> wrote:
>
> > In version 0.9.6 one used to be able to do this:
> >
> > In [4]: numpy.__version__
> > Out[4]: '0.9.6'
> >
> >
> > In [6]: numpy.array([numpy.array([4,5,6]), numpy.array([1,2,3])],
> > dtype=object).shape
> > Out[6]: (2, 3)
> >
> >
> > In beta 1 numpy.PyObject no longer exists.  I was trying to get the
> > same behavior with dtype=object but it doesn't work:
> >
> > In [7]: numpy.__version__
> > Out[7]: '1.0b1'
> >
> > In [8]: numpy.array([numpy.array ([4,5,6]), numpy.array([1,2,3])],
> > dtype=object).shape
> > Out[8]: (2,)
>
>
> The latter looks more correct, in that is produces an array of objects. To
> get the previous behaviour there is the function vstack:
>
> In [6]: a = array([1,2,3])
>
> In [7]: b = array([4,5,6])
>
> In [8]: vstack([a,b])
> Out[8]:
> array([[1, 2, 3],
>        [4, 5, 6]])
>
> Chuck
>
>
>
> -------------------------------------------------------------------------
> 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://mail.python.org/pipermail/numpy-discussion/attachments/20060831/bb22f376/attachment.html>


More information about the NumPy-Discussion mailing list