python中如何计算矩阵的1/2次方

2024-03-29 13:39:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python计算度矩阵的-1/2次方。我知道有一个很好的包可以计算networkx中的规范化图laplacian(L\u norm=I-D^{-1/2}AD^{-1/2},a是邻接矩阵)。但我只需要D^{-1/2}。你知道吗

我试过numpy.linalg.matrix_power,但它只支持整数。你知道吗

raise TypeError("exponent must be an integer") TypeError: exponent must be an integer

有没有办法计算矩阵的1/2次方?你知道吗


Tags: numpynetworkxannorm矩阵integerbe规范化
1条回答
网友
1楼 · 发布于 2024-03-29 13:39:28

您可以使用分数矩阵幂矩阵的分数次幂。
Example from Docs

>>> from scipy.linalg import fractional_matrix_power
>>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
# fractional power of a matrix
>>> b = fractional_matrix_power(a, 0.5)
>>> b
array([[ 0.75592895,  1.13389342],
       [ 0.37796447,  1.88982237]])
>>> np.dot(b, b)      # Verify square root
array([[ 1.,  3.],
       [ 1.,  4.]])

相关问题 更多 >