# [SciPy-User] raising a matrix to float power

Anne Archibald aarchiba@physics.mcgill...
Sat Jul 10 18:47:48 CDT 2010

```On 10 July 2010 19:26, Alexey Brazhe <brazhe@gmail.com> wrote:
> Hi,
> I failed to find a way to raise a matrix to a non-integer power in
> numpy/scipy
>
> In Octave/Matlab, one would write M^0.5 to get the result
> whereas in numpy
>>>> maxtrix(M, 0.5)
> raises the "TypeError: exponent must be an integer"
>
> Is there a way to do matrix exponentiation to non-integer powers in numpy or
> scipy?
>
> Hope the answer is positive :)

There are several, but you need to think carefully about what you're
actually trying to do, and what matrices you're going to try to do it
with. If you want the "matrix square root", that's obtained using the
cholesky decomposition but only makes sense for positive definite
matrices. If you want more general powers, scipy.linalg provides
"expm", "expm2", and "expm3", which all calculate notionally the same
thing (what you get by plugging a matrix into the Taylor series for
exp) in different ways; which one is the most accurate, efficient,
and/or applicable for your particular matrix will vary. scipy.linalg
also contains matrix versions of various other functions.

Anne
P.S. please keep in mind the distinction between "matrix" objects
(arrays with syntactic sugar for multiplication and exponentiation)
and matrix versions of various functions (which generally operate on
arrays). -A

> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
```