请看下面的代码。
import numpy as np
a = np.array([-1, -3, -1, -9, 2])
b = np.array([[-1, -3, -1, -9, 2]])
print("Infinity norm of a:", np.linalg.norm(a, ord=np.inf))
print("Infinity norm of b:", np.linalg.norm(b, ord=np.inf))
输出(Google Colab)是:
Infinity norm of a: 9.0
Infinity norm of b: 16.0
Numpy 版本是 1.25.2
Google Colab Python 版本是 3.10.12
请参阅上面的描述。我期待同样的结果。但一维和二维 arryas 的 L-inf 范数显然不同。
文档中的表格直接解释了差异!
https://numpy.org/doc/stable/reference/ generated/numpy.linalg.norm.html
命令 | 矩阵范数 | 向量范数 |
---|---|---|
|
|
|