Python Numpy matrix.conj() Function

NumPy Library 

NumPy is a library in python that is created to work efficiently with arrays in python. It is fast, easy to learn, and provides efficient storage. It also provides a better way of handling data for the process. We can create an n-dimensional array in NumPy. To use NumPy simply have to import it into our program and then we can easily use the functionality of NumPy in our program.

NumPy is a Python library that is frequently used for scientific and statistical analysis. NumPy arrays are grids of the same datatype’s values.

Numpy matrix.conj() Function:

We can obtain the conjugate of a given matrix with one or more dimensions using the matrix.conj() method of the Numpy module.

Syntax:

 matrix.conj()

Return Value:

The conjugate of a given matrix is returned by the matrix.conj() function.

Conjugate of a Matrix:

A conjugate matrix is a complex matrix in which all of its elements have been replaced by their complex conjugates, i.e. the sign of all the imaginary part of the complex numbers has been changed.

Example:

Let matrix = [1+3j,  2-4j]
conjugate of a matrix = [1-3j,  2+4j]

Numpy matrix.conj() Function in Python

For 1-Dimensional (1D) Matrix

Approach:

  • Import numpy module using the import keyword.
  • Create a complex matrix(1-Dimensional) using the matrix() function of numpy module by passing some random 1D matrix as an argument to it and store it in a variable.
  • Apply conj() function on the given matrix to get the conjugate of the given complex matrix
  • Store it in another variable.
  • Print the conjugate of the given complex matrix.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
            
# Create a complex matrix(1-Dimensional) using the matrix() function of numpy module by passing 
# some random 1D matrix as an argument to it and store it in a variable
gvn_matrx = np.matrix([1+3j, 2-4j])
            
# Apply conj() function on the given matrix to get the conjugate of the given complex matrix
# Store it in another variable
rslt = gvn_matrx.conj()
# Print the conjugate of the given complex matrix
print("The conjugate of the given complex matrix:")
print(rslt)

Output:

The conjugate of the given complex matrix:
[[1.-3.j 2.+4.j]]

For 2-Dimensional (2D) Matrix

Approach:

  • Import numpy module using the import keyword.
  • Create a complex matrix(1-Dimensional) using the matrix() function of numpy module by passing some random 1D matrix as an argument to it and store it in a variable.
  • Print the given complex matrix.
  • Apply conj() function on the given matrix to get the conjugate of the given complex matrix
  • Store it in another variable.
  • Print the conjugate of the given complex matrix.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
            
# Create a complex matrix(2-Dimensional) using the matrix() function of numpy module by passing 
# some random 2D matrix as an argument to it and store it in a variable
gvn_matrx = np.matrix([[2-3j, 3 + 1j], [-5 + 2j, 6-4j]])
# Print the given complex matrix. 
print("The given complex matrix:")   
print(gvn_matrx)       
            
# Apply conj() function on the given matrix to get the conjugate of the given complex matrix
# Store it in another variable
rslt = gvn_matrx.conj()
# Print the conjugate of the given complex matrix
print("The conjugate of the given complex matrix:")
print(rslt)

Output:

The given complex matrix:
[[ 2.-3.j 3.+1.j]
 [-5.+2.j 6.-4.j]]
The conjugate of the given complex matrix:
[[ 2.+3.j 3.-1.j]
 [-5.-2.j 6.+4.j]]