简体   繁体   English

计算 Python 中矩阵的 3 范数

[英]Calculating the 3-norm of a matrix in Python

I'm trying to calculate the 3-norm of the matrix y here but I keep getting an error that says我试图在这里计算矩阵 y 的 3 范数,但我一直收到一条错误消息

ValueError: Invalid norm order for matrices.

This is the code that I tried这是我试过的代码

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

I'm not sure how to go about calculating the 3-norm here so any help would be appreciated我不确定如何 go 在这里计算 3 范数所以任何帮助将不胜感激

You need to specify axis=0 in the norm method since you have a 5x1 matrix and you want to calculate the norm over column 1.您需要在norm方法中指定axis=0因为您有一个 5x1 矩阵并且您想要计算第 1 列的范数。

If you would have just a python list, it would be okay without.如果你只有一个 python 列表,没有它也没关系。

Cheers!干杯!

As seen in the norm documentation the standard inputs does not include order=3.正如标准文档中所见,标准输入不包括 order=3。

As stated in the post previous you need to add an axis parameter where x=0.如上一篇文章所述,您需要在 x=0 处添加一个轴参数。

try:尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM