How to use the numpy.conjugate() method for a 2-D array
The numpy.conjugate() method
The numpy.conjugate() method returns a complex conjugate of an input array that is passed to it. This is done element by element.
Note: In Python, we can use a list of lists to create a two-dimensional (2-D) array.
Syntax
numpy.conjugate(arr, /, out=None, *, where=True,)
Parameters
arr1: This represents the input array.out: This optional parameter specifies the location where the result is saved.where: This is an optional parameter representing the condition in which the input gets broadcasted.
Return value
The method numpy.conjugate() returns the complex element-wise conjugate of the input array passed to it.
Example
The following code shows how to use the numpy.conjugate() method for two-dimensional (2-D) arrays.
# import numpyimport numpy as np# create listx1 = [1+2j,1+5j,1+3j]x2 = [1+7j,1+2j,1+5j]# convert the lists to 2D array using np.arrayarr = np.array([x1,x2])# compute the complex array values# and store the result in resultresult = np.conjugate(arr)print(result)
Explanation
- Line 2: We add the
numpylibrary to the code. - Lines 4–5: We create two lists,
x1andx2. - Line 7: We use the
np.array()method to turn the lists into a 2-D array and save the result in a new variable namedarr. - Line 11: We compute the input array’s complex conjugate using the
np.conjugate()method and store the result in theresultvariable. - Line 13: We display the output.