Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.linalg.matrix_power

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

Raise a square matrix to the (integer) powern.

For positive integersn, the power is computed by repeated matrixsquarings and matrix multiplications. Ifn==0, the identity matrixof the same shape as M is returned. Ifn<0, the inverseis computed and then raised to theabs(n).

Parameters:
a:(…, M, M) array_like

Matrix to be “powered.”

n:int

The exponent can be any integer or long integer, positive,negative, or zero.

Returns:
a**n:(…, M, M) ndarray or matrix object

The return value is the same shape and type asM;if the exponent is positive or zero then the type of theelements is the same as those ofM. If the exponent isnegative the elements are floating-point.

Raises:
LinAlgError

For matrices that are not square or that (for negative powers) cannotbe inverted numerically.

Examples

>>>fromnumpy.linalgimportmatrix_power>>>i=np.array([[0,1],[-1,0]])# matrix equiv. of the imaginary unit>>>matrix_power(i,3)# should = -iarray([[ 0, -1],       [ 1,  0]])>>>matrix_power(i,0)array([[1, 0],       [0, 1]])>>>matrix_power(i,-3)# should = 1/(-i) = i, but w/ f.p. elementsarray([[ 0.,  1.],       [-1.,  0.]])

Somewhat more sophisticated example

>>>q=np.zeros((4,4))>>>q[0:2,0:2]=-i>>>q[2:4,2:4]=i>>>q# one of the three quaternion units not equal to 1array([[ 0., -1.,  0.,  0.],       [ 1.,  0.,  0.,  0.],       [ 0.,  0.,  0.,  1.],       [ 0.,  0., -1.,  0.]])>>>matrix_power(q,2)# = -np.eye(4)array([[-1.,  0.,  0.,  0.],       [ 0., -1.,  0.,  0.],       [ 0.,  0., -1.,  0.],       [ 0.,  0.,  0., -1.]])

Previous topic

numpy.einsum_path

Next topic

numpy.kron

Quick search

  • © Copyright 2008-2018, The SciPy community.
  • Last updated on Jul 24, 2018.
  • Created usingSphinx 1.6.6.

[8]ページ先頭

©2009-2025 Movatter.jp