mindspore.numpy.matrix_power

mindspore.numpy.matrix_power(a, n)[source]

Raises a square matrix to the (integer) power n.

For positive integers n, the power is computed by repeated matrix squarings and matrix multiplications. If \(n == 0\), the identity matrix of the same shape as M is returned.

Note

Stacks of object matrices are not currently supported and \(n < 0\) is not supported.

Parameters
Returns

Tensor.

Raises
  • TypeError – if the input can not be converted to a tensor or the exponent is not integer.

  • ValueError – if the input includes less than 2 dimensions or the last 2 dimensions are not square.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import numpy as np
>>> a = np.arange(16).reshape(4, 4).astype('float32')
>>> print(np.matrix_power(a, 2))
[[ 56.  62.  68.  74.]
 [152. 174. 196. 218.]
 [248. 286. 324. 362.]
 [344. 398. 452. 506.]]