计算 Python 中矩阵的 3 范数

Calculating the 3-norm of a matrix in Python

我在这里尝试计算矩阵 y 的 3 范数,但我一直收到一个错误

ValueError: Invalid norm order for matrices.

这是我试过的代码

    y = np.random.rand(5,1)
    print(y)
    p = 3
    ly = npla.norm(y,p)
    print('ly =',ly,)

我不确定如何在这里计算 3-范数,因此我们将不胜感激

您需要在 norm 方法中指定 axis=0,因为您有一个 5x1 矩阵并且您想要计算第 1 列的范数。

如果你只有一个 python 列表,没有它也没关系。

干杯!

norm documentation 中所示,标准输入不包括 order=3。

如前 post 所述,您需要添加一个轴参数,其中 x=0。

尝试:

np.linalg.norm(yourMatrix,3,axis=0)