Equivalent of j in NumPy Equivalent of j in NumPy python python

Equivalent of j in NumPy


In Python, 1j or 0+1j is a literal of complex type. You can broadcast that into an array using expressions, for example

In [17]: 1j * np.arange(5)Out[17]: array([ 0.+0.j,  0.+1.j,  0.+2.j,  0.+3.j,  0.+4.j])

Create an array from literals:

In [18]: np.array([1j])Out[18]: array([ 0.+1.j])

Note that what Michael9 posted creates a complex, not a complex array:

In [21]: np.complex(0,1)Out[21]: 1jIn [22]: type(_)Out[22]: complex


You can create one if needed or use 1j which instance of complex class

 >>> 1j #complex object 1j >>> type(1j) <class 'complex'> >>> j = np.complex(0,1) #create complex number >>> j 1j