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

Olivier Delalleau shish@keba...
Thu Apr 5 11:57:32 CDT 2012


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

> Ken Watford wrote:
>
> > On Thu, Apr 5, 2012 at 11:57 AM, Olivier Delalleau <shish@keba.be>
> wrote:
> >> Le 5 avril 2012 11:45, Neal Becker <ndbecker2@gmail.com> a écrit :
> >>
> >> You can do:
> >>
> >> f = numpy.frompyfunc(lambda x: x.some_attribute == 0, 1, 1)
> >>
> >> Then
> >> f(array_of_objects_x)
> >
> > This is handy too:
> >
> > agetattr = numpy.frompyfunc(getattr, 2, 1)
> >
> > array_of_values = agetattr(array_of_objects, 'some_attribute')
>
> I suppose for setitem something similar, except I don't think you can do
> that
> with lambda since lambda doesn't allow an assignment.
>

You can call setattr in a lambda though, to bypass the assignment
limitation.

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


More information about the NumPy-Discussion mailing list