NumPy conj() Function:
The conj() method of the NumPy module returns the element-by-element complex conjugate of the given array.
A complex number’s conjugate is obtained by changing the sign of its imaginary part.
For example, the conjugate of a complex number of 1+3j is 1-3j.
Syntax:
numpy.conj(a, out=None)
Parameters
a: This is required. It is an array given as input.
out: This is optional. It is the location where the result will be stored. It must have a shape that the inputs broadcast to if it is provided. If None or not given, a newly allocated array is returned.
Return Value:
The element-by-element complex conjugate of the given array is returned by the conj() method of the NumPy module
NumPy conj() Function in Python
Example1: (For 1-Dimensional Array)
Approach:
- Import numpy module using the import keyword
- Pass some random complex numbers list(1-Dimensional) as an argument to the
array() function to create an array. - Store it in a variable.
- Print the above-given array.
- Pass the above-given array as an argument to the conj() function of the numpy module to get the conjugate of all the complex elements of the given array.
- Store it in another variable.
- Print the conjugate of all the elements of the given complex array.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(1-Dimensional) as an argument to the
# array() function to create an array.
# Store it in a variable.
gvn_arry = np.array([1+3j, 4+3j, 2+2j,-1-5j])
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the conj() function of the
# numpy module to get the conjugate of all the complex elements of
# the given array
# Store it in another variable.
rslt = np.conj(gvn_arry)
# Print the conjugate of all the elements of the given complex array
print("The conjugate of all the elements of the given complex array:")
print(rslt)
Output:
The above given array is: [ 1.+3.j 4.+3.j 2.+2.j -1.-5.j] The conjugate of all the elements of the given complex array: [ 1.-3.j 4.-3.j 2.-2.j -1.+5.j]
Example2: (For n-Dimensional Array, where n is an integer)
Approach:
- Import numpy module using the import keyword
- Pass some random complex numbers list(n-Dimensional) as an argument to the
array() function to create an array. - Store it in a variable.
- Print the above-given array.
- Pass the above-given array as an argument to the conj() function of the numpy module to get the conjugate of all the complex elements of the given array.
- Store it in another variable.
- Print the conjugate of all the elements of the given complex array.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(n-Dimensional) as an argument to the
# array() function to create an array.
# Store it in a variable.
gvn_arry = np.array([[1-3j, 4+3j],
[-2-4j, 5+6j]])
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array as an argument to the conj() function of the
# numpy module to get the conjugate of all the complex elements of
# the given array
# Store it in another variable.
rslt = np.conj(gvn_arry)
# Print the conjugate of all the elements of the given complex array
print("The conjugate of all the elements of the given complex array:")
print(rslt)
Output:
The above given array is: [[ 1.-3.j 4.+3.j] [-2.-4.j 5.+6.j]] The conjugate of all the elements of the given complex array: [[ 1.+3.j 4.-3.j] [-2.+4.j 5.-6.j]]