简体   繁体   中英

Is the numpy documentation for calculating the 2nd order norm of a matrix across the columns slightly misleading?

I was trying to figure out how to calculate the Frobenius of a matrix in numpy. This way I can get the 2-norm of each row in the matrix x below: My question is about the ord parameter in numpy's linalg.norm module and how the relevant part of numpy documentation describes which norm of a matrix one can calculate. I was able to get the Frobenius norm by setting ord=2 , however, it says that only setting ord=None gives the Frobenius norm.

numpy文档中提供的表

Here is my example:

x = np.array([[0, 3, 4],
          [1, 6, 4]])

I found that I can the Frobenius norm with the following line of code:

x_norm = np.linalg.norm(x, ord = 2, axis=1,keepdims=True )

>>> x_norm
    array([[ 5.        ],
           [ 7.28010989]])

My question is whether the documentation here would be considered not as helpful as possible and if this warrants a request to change the description of setting ord=2 in the aforementioned table.

You're not taking a matrix norm. Since you've passed axis=1 , you're taking vector norms, and you should be looking at the vector norm column instead of the matrix norm column.

For vector norms, ord=None and ord=2 both produce a 2-norm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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