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 

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to