[Numpy-discussion] ndarray of complex-like data
Brecht Machiels
brecht.machiels at esat.kuleuven.be
Wed Feb 17 03:43:37 EST 2010
Robert Kern wrote:
>>> 2) Subclass the ndarray to do what you want.
>> I have subclassed ndarray, but I'm not sure how to continue from there.
>> I was thinking of overriding __getitem__ and casting the complex to my
>> complex subclass. Would that be the way to go? How would that work with
>> slices?
>
> I strongly recommend simply implementing an arg() function that works
> on both arrays and and complex objects. Then just use abs() and arg()
> instead of trying to get instances of your class and using their
> attributes.
Hmm. I hadn't thought of that option. I guess this makes more sense as
this can than also operate on arrays like you say.
Still, it would be interesting to know whether it's possible to have an
ndarray subclass return instances of my complex subclass, preferably
without having to copy the complex data (which would occur if I were to
implement this behaviour by overriding __getitem__ as described above).
But I assume that would require a user-defined type written in C?
Regards,
Brecht
More information about the NumPy-Discussion
mailing list