[Numpy-discussion] checking element types in array
Zoho Vignochi
zoho.vignochi@gmail....
Sat May 17 10:02:32 CDT 2008
hello:
I am writing my own version of a dot product. Simple enough this way:
def dot_r(a, b):
return sum( x*y for (x,y) in izip(a, b) )
However if both a and b are complex we need:
def dot_c(a, b):
return sum( x*y for (x,y) in izip(a.conjugate(), b) ).real
I would like to combine these so that I need only one function which
detects which formula based on argument types. So I thought that
something like:
def dot(a,b):
if isinstance(a.any(), complex) and isinstance(b.any(), complex):
return sum( x*y for (x,y) in izip(a.conjugate(), b) ).real
else:
return sum( x*y for (x,y) in izip(a, b) )
And it doesn't work because I obviously have the syntax for checking
element types incorrect. So my real question is: What is the best way to
check if any of the elements in an array are complex?
Thank you,
Zoho
More information about the Numpy-discussion
mailing list