from numpy.linalg import norm
时间: 2023-11-19 09:05:08 浏览: 115
numpy基础教程之np.linalg
The `norm` function from `numpy.linalg` module is used to calculate various matrix and vector norms. It takes an array-like object as input and returns the norm of that object. The norm can be specified using the optional `ord` parameter, which can take values like 1, 2, -1, -2, etc.
For example, to calculate the Euclidean norm of a vector `v`, we can use the following code:
```
import numpy as np
v = np.array([1, 2, 3])
norm_v = np.linalg.norm(v)
print(norm_v)
```
This will output `3.74165738677`, which is the Euclidean norm of the vector `[1, 2, 3]`.
阅读全文