[Numpy-discussion] apply 'getitem to each element of obj array?

Olivier Delalleau shish@keba...
Thu Apr 5 10:57:56 CDT 2012


Le 5 avril 2012 11:45, Neal Becker <ndbecker2@gmail.com> a écrit :

> Adam Hughes wrote:
>
> > If you are storing objects, then can't you store them in a list and just
> do:
> >
> > for obj in objectlist:
> >      obj.attribute = value
> >
> > Or am I misunderstanding?
> >
>
> It's multi-dimensional, and I wanted to avoid writing explicit loops.
>

You can do:

f = numpy.frompyfunc(lambda x: x.some_attribute == 0, 1, 1)

Then
f(array_of_objects_x)

-=- Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120405/e1578343/attachment.html 


More information about the NumPy-Discussion mailing list