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.H() Function:
We can build a conjugate Transpose of any complex matrix with dimensions one or more than one using the numpy.matrix.H() method of the Numpy module.
Syntax:
numpy.matrix.H()
Return Value:
The conjugate transpose of every complex matrix is returned by the matrix.H() function.
Transpose of a Matrix
The transpose of a matrix is one of the most often used methods in matrix transformation in linear algebra.
The transpose of a matrix for a given matrix is obtained by swapping/interchanging rows into columns or columns to rows.
For Example:
Let the matrix be: [1 2] [3 4] Transpose of a matrix is: [1 3] [2 4]
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.H() Function in Python
For 1-Dimensional (1D) Matrix
Here the getH() function performs conjugate and the transpose operations simultaneously on a given complex 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 getH() function on the given matrix to get the conjugate Transpose of the given complex matrix
- Store it in another variable
- Print the conjugate Transpose 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 getH() function on the given matrix to get the conjugate Transpose of the given complex matrix # Store it in another variable rslt = gvn_matrx.getH() # Print the conjugate Transpose of the given complex matrix print("The conjugate Transpose of the given complex matrix:") print(rslt)
Output:
The conjugate Transpose 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(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
- Print the given complex matrix.
- Apply getH() function on the given matrix to get the conjugate Transpose of the given complex matrix
- Store it in another variable
- Print the conjugate Transpose 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 getH() function on the given matrix to get the conjugate Transpose of the given complex matrix # Store it in another variable rslt = gvn_matrx.getH() # Print the conjugate Transpose of the given complex matrix print("The conjugate Transpose 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 Transpose of the given complex matrix: [[ 2.+3.j -5.-2.j] [ 3.-1.j 6.+4.j]]