Search code examples
pythonnumpymatrixcomplex-numbers

How can I use this complex number in numpy matrix?


Here's the Python code I'm working on:

def inver_hopf(x,y,z):
    return (1/np.sqrt(x**2+y**2+(1+z)**2))*np.matrix([[1+z],[x+y.j]],dtype=complex)

The problem happens at [x+y.j], where j means complex unit. It returns me the error message AttributeError: 'int' object has no attribute 'j'. If I remove the dot, then it returns NameError: name 'yj' is not defined. How can I correct that? Thanks!


Solution

  • j alone is a variable, you can have the complex number by typing 1j