[Numpy-discussion] checking element types in array

Zoho Vignochi zoho.vignochi at gmail.com
Sun May 18 09:59:10 EDT 2008


On Sat, 17 May 2008 14:58:20 -0400, Anne Archibald wrote:

> numpy arrays are efficient, among other reasons, because they have
> homogeneous types. So all the elements in an array are the same type.
> (Yes, this means if you have an array of numbers only one of which
> happens to be complex, you have to represent them all as complex numbers
> whose imaginary part happens to be zero.) So if A is an array A.dtype is
> the type of its elements.
> 
> numpy provides two convenience functions for checking whether an array
> is complex, depending on what you want:
> 
> iscomplex checks whether each element has a nonzero imaginary part and
> returns an array representing the element-by-element answer; so
> any(iscomplex(A)) will be true if any element of A has a nonzero
> imaginary part.
> 
> iscomplexobj checks whether the array has a complex data type. This is
> much much faster, but of course it may happen that all the imaginary
> parts happen to be zero; if you want to treat this array as real, you
> must use iscomplex.
> 
> Anne
> 
> 
> Anne

Thank you for the explanation. I knew there would be a speed penalty but 
the current numpy dot doesn't work as expected with mpf or mpc just yet 
and so I had to write my own. Your explanation helped as I decided to 
treat all numbers as complex and just implemented the complex version.

Thanks,  Zoho




More information about the NumPy-Discussion mailing list