[Numpy-discussion] how to create an array of objects that are sequences?
Charles R Harris
charlesr.harris@gmail....
Fri Jan 4 12:33:36 CST 2008
On Jan 4, 2008 11:13 AM, Pearu Peterson <pearu@cens.ioc.ee> wrote:
> On Fri, January 4, 2008 7:33 pm, Travis E. Oliphant wrote:
>
> > So, create an empty object array and insert the entries the way you want
> > them:
> >
> > a = np.empty(1,dtype=object)
> > a[0] = A((1,2))
>
> Actually this is still an option if to put the above
> to a A.as_array method something like
>
> class A(tuple):
> def as_array(self):
> import numpy
> obj = numpy.empty(1,dtype=object)
> obj[0] = self
> return obj
>
> but it would be nice if the __array__ method also worked.
> Could this be something that should be put to issues or
> would it just get a WontFix flag?
IIRC the previous discussions, there simply isn't enough information in the
array interface to decide what needs to be done with regards to object
arrays. I think a general solution would require a specialized creation
function with more arguments, say, a depth argument which would create
objects at a certain depth of nesting. In your case that would be at level
0(1?). I think that would solve most problems, and I suppose it could be
added to the current array interface with a default value implying current
behavior, i.e., as deep as possible.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080104/97acae2b/attachment.html
More information about the Numpy-discussion
mailing list