[英]Getting different answers with MATLAB and Python norm functions
I am getting two vastly different answers with regards to simple matrix norms when comparing the MATLAB and Python functions. 在比较MATLAB和Python函数时,我得到了关于简单矩阵规范的两个截然不同的答案。
Let 让
R =
0.9940 0.0773 -0.0773
-0.0713 0.9945 0.0769
0.0828 -0.0709 0.9940
Then in MATLAB: 然后在MATLAB中:
>> norm(R)
ans =
1
But in Python 但在Python中
from scipy.linalg import norm
import numpy as np
print norm(R),np.linalg.norm(R)
1.73205080757 1.73205080757
where 哪里
print scipy.__version__,np.__version__
0.14.0 1.9.0
How did I manage to so comprehensively screw that up? 我是如何全面搞砸的呢?
Either do this in MATLAB: 要么在MATLAB中这样做:
>> norm(R,'fro')
or this in Python: 或者在Python中:
>>> np.linalg.norm(R,2)
Matlab default for matrix norm is the 2-norm while scipy and numpy's default to the Frobenius norm for matrices. 矩阵范数的Matlab默认值是2范数,而scipy和numpy默认为矩阵的Frobenius范数。 Specifying the norm explicitly should fix it for you
明确指定规范应该为您解决
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.