在 Matlab 中,为什么整个矩阵的 L2 范数的平方与 row/column 明智的 L2 范数的平方和不匹配?

In Matlab, why does square of L2 Norm of whole matrix does not matches to sum of square of row/column wise L2 Norm?

矩阵的 L2-Norm 的平方应匹配所有 rows/columns L2-Norm 的平方和。 参考:http://mathworld.wolfram.com/L2-Norm.html

考虑在 Matlab 中遵循随机 (4,3) 矩阵

Computed using a = rand(4,3)

0.0400    0.4357    0.9144
0.5551    0.9048    0.5755
0.1675    0.1772    0.3001
0.4189    0.0403    0.2407

整个矩阵的L2范数为:

norm(a1)^2 = 2.7806

列平方和的 L2 范数:

norm(a1(:,1))^2 + norm(a1(:,2))^2 + norm(a1(:,3))^2 = 2.9337

行平方和的L2范数:

norm(a1(1,:))^2 + norm(a1(2,:))^2 + norm(a1(3,:))^2 = 2.2214

因为,这在 Python (numpy) 中匹配:

a = np.random.rand(4,3)
array([[ 0.91033221,  0.9082118 ,  0.6864961 ],
   [ 0.15157616,  0.70232112,  0.06709103],
   [ 0.61008197,  0.15648347,  0.02693866],
   [ 0.53646277,  0.22186601,  0.77530143]])

整个矩阵的L2范数

numpy.linalg.norm(a)**2 = 3.9810836846898465

L2 行平方和范数:

numpy.linalg.norm(a[0])**2  + numpy.linalg.norm(a[1])**2  + 
numpy.linalg.norm(a[2])**2 + numpy.linalg.norm(a[3])**2 = 3.9810836846898465

Matlab 不是在进行更高精度的运算吗,它累积地累加了 Whole Matrix Norm 和 Row-Column 的差异?

Matlab 中是否有任何选项可以让我正确地执行此操作?

Matlab 对矩阵使用的范数与向量不同。来自 norm 的 Matlab 文档:

n = norm(X) returns the 2-norm or maximum singular value of matrix X, which is approximately max(svd(X)).

因此,要获得与行和列计算类似的结果,您必须对矩阵进行向量化。

M =[0.0400, 0.4357, 0.9144;
    0.5551, 0.9048, 0.5755;
    0.1675, 0.1772, 0.3001;
    0.4189, 0.0403, 0.2407 ];

norms = [];
norms(end+1) = norm(M)^2;    % 2.46
norms(end+1) = norm(M(:))^2; % 2.87
norms(end+1) = norm(M(1,:))^2 + norm(M(2,:))^2 + norm(M(3,:))^2 + norm(M(4,:))^2; % 2.87
norms(end+1) = norm(M(:,1))^2 + norm(M(:,2))^2 + norm(M(:,3))^2; % 2.87

norms