为什么当我尝试将对称矩阵对角线化时,为什么不是t`np.linalg.eig返回统一矩阵?
使用Python,我创建了一个对称矩阵x
,并使用代码lambda,u = np.linalg.eig(x)
对对角线化。我的理解是:由于x
是对称的,u
应该是统一的,但我发现事实并非如此,因为u
具有eigenvalues这没有绝对值1
,这也意味着这也不是缩放问题。我的问题是为什么u
不统一?
这是一个最小可重现的示例,可以查看我得到的内容:
import numpy as np
#Symmetric matrix, which should be diagonalized by unitary
X = np.array([[-1.1918157 , 0. , 0. , 0. , 0.09852097,
0. , 0. , 0. ],
[ 0. , -1.1918157 , 0. , 0. , 0. ,
0.09852097, 0. , 0. ],
[ 0. , 0. , -1.08529969, 0. , 0. ,
0. , 0.07826825, 0. ],
[ 0. , 0. , 0. , -1.08529969, 0. ,
0. , 0. , 0.07826825],
[ 0.09852097, 0. , 0. , 0. , -1.00585682,
0. , 0. , 0. ],
[ 0. , 0.09852097, 0. , 0. , 0. ,
-1.00585682, 0. , 0. ],
[ 0. , 0. , 0.07826825, 0. , 0. ,
0. , -0.98276093, 0. ],
[ 0. , 0. , 0. , 0.07826825, 0. ,
0. , 0. , -0.98276093]])
#check if X is symmetric
assert np.linalg.norm(X - X.conj().T) == 0
#diagonalize X
Lambda, U = np.linalg.eig(X)
#check if U is unitary
print(
np.allclose(U @ U.conj().T, np.identity(U.shape[0])),
np.allclose(U.conj().T, np.linalg.inv(U))
)
#Since the above returns false, how non-unitary is it?
print(
np.linalg.norm(U @ U.conj().T - np.identity(U.shape[0])),
np.linalg.norm(U.conj().T - np.linalg.inv(U))
)
上述代码的输出是:
False False
0.994793051566498 1.1641788210519939
Using Python, I created a symmetric matrix X
, and diagonalized it using the code Lambda, U = np.linalg.eig(X)
. My understanding is: since X
is symmetric, U
should be unitary, but I am finding that this is not the case, as U
has eigenvalues that don't have absolute value 1
, which also means that this is not a scaling issue either. My question is why is U
not unitary?
Here is a minimum reproducible example to see what I am getting:
import numpy as np
#Symmetric matrix, which should be diagonalized by unitary
X = np.array([[-1.1918157 , 0. , 0. , 0. , 0.09852097,
0. , 0. , 0. ],
[ 0. , -1.1918157 , 0. , 0. , 0. ,
0.09852097, 0. , 0. ],
[ 0. , 0. , -1.08529969, 0. , 0. ,
0. , 0.07826825, 0. ],
[ 0. , 0. , 0. , -1.08529969, 0. ,
0. , 0. , 0.07826825],
[ 0.09852097, 0. , 0. , 0. , -1.00585682,
0. , 0. , 0. ],
[ 0. , 0.09852097, 0. , 0. , 0. ,
-1.00585682, 0. , 0. ],
[ 0. , 0. , 0.07826825, 0. , 0. ,
0. , -0.98276093, 0. ],
[ 0. , 0. , 0. , 0.07826825, 0. ,
0. , 0. , -0.98276093]])
#check if X is symmetric
assert np.linalg.norm(X - X.conj().T) == 0
#diagonalize X
Lambda, U = np.linalg.eig(X)
#check if U is unitary
print(
np.allclose(U @ U.conj().T, np.identity(U.shape[0])),
np.allclose(U.conj().T, np.linalg.inv(U))
)
#Since the above returns false, how non-unitary is it?
print(
np.linalg.norm(U @ U.conj().T - np.identity(U.shape[0])),
np.linalg.norm(U.conj().T - np.linalg.inv(U))
)
The output of the above code is:
False False
0.994793051566498 1.1641788210519939
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
永远无法保证返回统一矩阵。
从这一行代码中,您可以找到
x
的特征值(存储在lambda
中)及其右eigenVectors (存储在矩阵中u中
)。参见 doc 。这里唯一的统一事物是特征向量,它是
u
的列。阅读有关特征值和特征向量的更多信息: wolfram
It's never guaranteed to return a unitary matrix.
From this line of code, you are finding eigenvalues of
X
(stored inLambda
) and its right eigenvectors (stored in matrixU
). See the doc.The only unitary things here are the eigenvectors, which are the columns of
U
.Read more about eigenvalues and eigenvectors: wiki, wolfram