From: Charles R H. <cha...@gm...> - 2006-08-31 17:57:53
|
On 8/31/06, Charles R Harris <cha...@gm...> wrote: > > On 8/31/06, Tom Denniston <tom...@al...> wrote: > > > But i have hetergenious arrays that have numbers and strings and > > NoneType, etc. > > > > Take for instance: > > > > In [11]: numpy.array([numpy.array([1,'A', None]), > > numpy.array([2,2,'Some string'])], dtype=object) > > Out[11]: > > array([[1, A, None], > > [2, 2, Some string]], dtype=object) > > > > In [12]: numpy.array([numpy.array([1,'A', None]), > > numpy.array([2,2,'Some string'])], dtype=object).shape > > Out[12]: (2, 3) > > > > Works fine in Numeric and pre beta numpy but in beta numpy versions i > > get: > > > I think you want: > > In [59]: a = array([array([1,'A', None],dtype=object),array([2,2,'Some > string'],dtype=object)]) > > In [60]: a.shape > Out[60]: (2, 3) > > Which makes good sense to me. > OK, I changed my mind. I think you are right and this is a bug. Using svn revision 3098 I get In [2]: a = array([1,'A', None]) --------------------------------------------------------------------------- exceptions.TypeError Traceback (most recent call last) /home/charris/<ipython console> TypeError: expected a readable buffer object Which is different than you get with beta 1 in any case. I think array should cast the objects in the list to the first common dtype, object in this case. So the previous should be shorthand for: In [3]: a = array([1,'A', None], dtype=object) In [4]: a.shape Out[4]: (3,) Chuck |