mindspore.numpy.matrix_power

mindspore.numpy.matrix_power(a, n)[源代码]

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.

说明

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

参数
返回

Tensor.

异常
  • 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

样例

>>> 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.]]