In this python numpy program, we will get the magnitude of a NumPy vector.
Steps to solve the program
- Import the numpy library as np.
- Create a vector using np.array().
- Get the magnitude of the vector using np.linalg.norm().
- Print the output.
import numpy as np
x = np.array([3, 5, 1])
print("Magnitude of the given vector: ",np.linalg.norm(x))
Output :
Magnitude of the given vector: 5.916079783099616