matrix_power(a, 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. If n < 0
, the inverse is computed and then raised to the abs(n)
.
Matrix to be "powered".
The exponent can be any integer or long integer, positive, negative, or zero.
For matrices that are not square or that (for negative powers) cannot be inverted numerically.
The return value is the same shape and type as :None:None:`M`
; if the exponent is positive or zero then the type of the elements is the same as those of :None:None:`M`
. If the exponent is negative the elements are floating-point.
Raise a square matrix to the (integer) power n
.
>>> from numpy.linalg import matrix_power
... i = np.array([[0, 1], [-1, 0]]) # matrix equiv. of the imaginary unit
... matrix_power(i, 3) # should = -i array([[ 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. 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.]])
>>> matrix_power(q, 2) # = -np.eye(4) array([[-1., 0., 0., 0.], [ 0., -1., 0., 0.], [ 0., 0., -1., 0.], [ 0., 0., 0., -1.]])See :
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.ufunc.square
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them