dpnp.linalg.matrix_power

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

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

For full documentation refer to numpy.linalg.matrix_power.

Parameters:
  • a ((..., M, M) {dpnp.ndarray, usm_ndarray}) -- Matrix to be "powered".

  • n (int) -- The exponent can be any integer or long integer, positive, negative, or zero.

Returns:

a**n -- The return value is the same shape and type as M; if the exponent is positive or zero then the type of the elements is the same as those of M. If the exponent is negative the elements are floating-point.

Return type:

(..., M, M) dpnp.ndarray

Examples

>>> import dpnp as np
>>> i = np.array([[0, 1], [-1, 0]]) # matrix equiv. of the imaginary unit
>>> np.linalg.matrix_power(i, 3) # should = -i
array([[ 0, -1],
       [ 1,  0]])
>>> np.linalg.matrix_power(i, 0)
array([[1, 0],
       [0, 1]])
>>> np.linalg.matrix_power(i, -3) # should 1/(-i) = i, but w/ f.p. elements
array([[ 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 1
array([[ 0., -1.,  0.,  0.],
       [ 1.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  1.],
       [ 0.,  0., -1.,  0.]])
>>> np.linalg.matrix_power(q, 2) # = -np.eye(4)
array([[-1.,  0.,  0.,  0.],
       [ 0., -1.,  0.,  0.],
       [ 0.,  0., -1.,  0.],
       [ 0.,  0.,  0., -1.]])