# [Numpy-tickets] [NumPy] #601: function for computing powers of a matrix

NumPy numpy-tickets@scipy....
Sun Oct 28 00:03:12 CDT 2007

#601: function for computing powers of a matrix
--------------------------+-------------------------------------------------
Reporter:  LevGivon      |       Owner:  somebody
Type:  enhancement   |      Status:  new
Priority:  normal        |   Milestone:
Component:  numpy.linalg  |     Version:  devel
Severity:  normal        |    Keywords:
--------------------------+-------------------------------------------------
It would be nice to add the following function to numpy to allow for the
raising of matricies to arbitrary exponents (and perhaps modify
`matrix.__pow__()` to use this approach when one attempts to raise a
matrix to a noninteger exponent):

{{{
from numpy import diag,dot,shape,eye
from numpy.linalg import eig,inv

def mpower(x,y):
'''Compute x raised to the power y when x is a square matrix and y
is a scalar.'''

s = shape(x)
if len(s) != 2 or s[0] != s[1]:
raise ValueError('matrix must be square')
if y == 0:
return eye(s[0])
[e,v] = eig(x)
d = diag(e)
return dot(dot(v,d**y),inv(v))
}}}

--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/601>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.