[Numpy-discussion] ndarray of complex-like data

Travis Oliphant oliphant at enthought.com
Tue Feb 16 08:23:24 EST 2010


On Feb 16, 2010, at 5:00 AM, Brecht Machiels wrote:

> Hello,
>
> I have written a subclass of Python's complex type, which only adds a
> couple of properties that return values calculated from the real and
> imaginary parts (magnitude and angle, for example).
>
> Now I would like to store objects of this new type in an ndarray. As  
> the
> new type doesn't store more information than a complex number, the
> ndarray's dtype can be 'complex'. I also assume that is is better for
> performance to use dtype=complex instead of dtype=object? Using
> dtype=complex also ensures that anything put into the array can be  
> cast
> to a complex.
>
> However, I would like the array to return objects of my new type  
> when I
> retrieve an item from the ndarray. I'm not sure how to do that. I  
> would
> rather avoid having to define the new type in C.

I see two options:

1) Write a user defined type in C --- there is a floatint example in  
the doc directory you can use as guidance.
2) Subclass the ndarray to do what you want.


-Travis



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100216/0b918b60/attachment.html>


More information about the NumPy-Discussion mailing list