Raise a square matrix to the power n in Linear Algebra using NumPy in Python Last Updated : 05 Jun, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to raise a square matrix to the power n in the Linear Algebra in Python. The numpy.linalg.matrix_power() method is used to raise a square matrix to the power n. It will take two parameters, The 1st parameter is an input matrix that is created using a NumPy array and the 2nd parameter is the exponent n, which refers to the power that can be zero or non-zero integers. Syntax: numpy.linalg.matrix_power(input_numpy_matrix,n) Parameters: input_numpy_matrix is the matrix.n refers to the integer value thar raise the matrix. Return: It will return matrix that is raised to power n Example 1 In this example, we are creating a 2D array (matrix) with 2 rows and 2 columns and returning the matrix raised to 0th power, matrix raised to 4th power, and matrix raised to 5th power. Python3 # import numpy and matrix_power import numpy from numpy.linalg import matrix_power # Create a 2D array input_array = numpy.array([[3, 4], [4, 5]]) # Display array print(input_array) # Using numpy.linalg.matrix_power() to # return raise 0 th power of matrix print(matrix_power(input_array, 0)) print() # Using numpy.linalg.matrix_power() to # return raise 4 th power of matrix print(matrix_power(input_array, 4)) print() # Using numpy.linalg.matrix_power() to # return raise 5 th power of matrix print(matrix_power(input_array, 5)) Output: [[3 4] [4 5]] [[1 0] [0 1]] [[1649 2112] [2112 2705]] [[13395 17156] [17156 21973]]Example 2 In this example, we are creating a 2D array (matrix) with 4 rows and 4 columns and returning the matrix raised to 0th power, matrix raised to 4th power, and matrix raised to 5th power. Python3 # import numpy and matrix_power import numpy from numpy.linalg import matrix_power # Create a 2D array input_array = numpy.array( [[3, 4, 3, 4], [4, 5, 2, 2], [1, 1, 0, -2], [-4, 5, 4, -1]]) # Display array print(input_array) # Using numpy.linalg.matrix_power() to # return raise 0 th power of matrix print(matrix_power(input_array, 0)) print() # Using numpy.linalg.matrix_power() to # return raise 4 th power of matrix print(matrix_power(input_array, 4)) print() # Using numpy.linalg.matrix_power() to # return raise 5 th power of matrix print(matrix_power(input_array, 5)) Output: [[ 3 4 3 4] [ 4 5 2 2] [ 1 1 0 -2] [-4 5 4 -1]] [[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]] [[2229 3622 1887 1354] [2460 4369 2238 1300] [ 237 839 426 2] [ 102 1206 864 441]] [[17646 35683 19347 11032] [21894 40423 21318 12802] [ 4485 5579 2397 1772] [ 4230 9507 4482 651]] Comment More infoAdvertise with us Next Article Raise a square matrix to the power n in Linear Algebra using NumPy in Python sravankumar_171fa07058 Follow Improve Article Tags : Python Python-numpy Python numpy-Linear Algebra Practice Tags : python Similar Reads Return the infinity Norm of the matrix in Linear Algebra using NumPy in Python In this article, we will how to return the infinity Norm of the matrix in Linear Algebra in Numpy using Python. numpy.linalg.norm() method The numpy.linalg.norm() method returns the matrix's infinite norm in Python linear algebra. This function can return one of eight possible matrix norms or an inf 3 min read Raise Chebyshev series to a power using NumPy in Python In this article, we will cover how to raise a Chebyshev series to power in Python using NumPy. polynomial.chebyshev.chebpow method The Chebyshev polynomials are like the other classical orthogonal polynomials which can be defined from a variety of starting locations. Â Here, we will see how to raise 3 min read Return the Norm of the vector over given axis in Linear Algebra using NumPy in Python In this article, we will how to return the Norm of the vector over a given axis in Linear Algebra in Python. numpy.linalg.norm() method The numpy.linalg.norm() method is used to return the Norm of the vector over a given axis in Linear algebra in Python. Depending on the value of the ord parameter, 3 min read Generate a Vandermonde matrix of the Legendre series in Python using NumPy In this article, we will be looking toward the approach to generating a Vandermonde matrix of the Legendre series in Python using NumPy. Example: Array: [-1 2 -3 4 -5] Result: [[ 1. -1. 1. ] [ 1. 2. 5.5] [ 1. -3. 13. ] [ 1. 4. 23.5] [ 1. -5. 37. ]]NumPy.legvander() To generate a pseudo Vandermonde m 3 min read Compute the determinant of a given square array using NumPy in Python In Python, the determinant of a square array can be easily calculated using the NumPy package. This package is used to perform mathematical calculations on single and multi-dimensional arrays. numpy.linalg is an important module of NumPy package which is used for linear algebra. We can use det() fun 2 min read How to get the number of dimensions of a matrix using NumPy in Python? In this article, we will discuss how to get the number of dimensions of a matrix using NumPy. It can be found using the ndim parameter of the ndarray() method. Syntax: no_of_dimensions = numpy.ndarray.ndim Approach: Create an n-dimensional matrix using the NumPy package.Use ndim attribute available 3 min read Multiplication of two Matrices in Single line using Numpy in Python Matrix multiplication is an operation that takes two matrices as input and produces single matrix by multiplying rows of the first matrix to the column of the second matrix.In matrix multiplication make sure that the number of columns of the first matrix should be equal to the number of rows of the 3 min read Multiply one Hermite series to another in Python using NumPy In this article, we are going to see how to multiply one Hermite series to another in Python Using NumPy. The NumPy polynomial.hermite.hermmul() is used to Multiply one Hermite series by another series. The product of two Hermite series c1 * c2 is returned. The arguments are sequences of coefficient 2 min read Raise a Hermite series to a power in Python The Hermite polynomials, like the other classical orthogonal polynomials, can be defined from a variety of starting locations. In this article let's see how to Raise a Hermite series to a power in Python. The NumPy package provides us polynomial.hermite.hermpow() method to raise a Hermite series. Sy 3 min read How to upsample a matrix by repeating elements using NumPy in Python? Prerequisites: Numpy Upsampling a matrix simply means expanding it and obviously upsampling can be done by adding more elements to the original matrix. It can be done in various ways like adding new elements and expanding the original matrix or it can be done by the matrix elements of original matri 2 min read Like