在Python中,如何将表示为numpy.ndarray的方阵提高为非整数幂? [英] In Python, how can I raise a square matrix represented as a numpy.ndarray to non-integer powers?

查看:193
本文介绍了在Python中,如何将表示为numpy.ndarray的方阵提高为非整数幂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个平方矩阵,该矩阵可以提高到-1/2幂. 我想将表示为numpy.ndarray的方阵提高到-1/2.

Assume I have a square matrix which can be raised to the -1/2 power. I want to raise the square matrix represented as a numpy.ndarray to -1/2.

请注意,我想将矩阵提高为非整数幂.我不想将矩阵的每个元素提升为非整数幂.

Note I want to raise the matrix to a non-integer power. I do not want raise each element of the matrix to a non-integer power.

我知道我可以按照

I know I can raise a matrix to an integer power using numpy.linalg.matrix_power as described in How to raise a numpy array to a power?

如何将numpy.ndarray提升为非整数幂?

How can I raise a numpy.ndarray to non-integer powers?

推荐答案

SciPy具有

SciPy has scipy.linalg.sqrtm, which computes a matrix square root. It's not clear whether it attempts to compute any particular square root - for example, the principal square root - but if the input has square roots, sqrtm will compute one. Thus, you can do

invsqrt = scipy.linalg.sqrtm(scipy.linalg.inv(input_matrix))

尽管您可能要进行一些错误处理.

though you'll likely want to do some error-handling.

这篇关于在Python中,如何将表示为numpy.ndarray的方阵提高为非整数幂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆