Python Practice › NumPy Programs › Program 77
Magnitude of a vector
Write a NumPy program to get the magnitude (length) of a vector.
Input
[3, 5, 1]
Output
5.92
Approach
np.linalg.norm.
Solution
import numpy as npprint(round(float(np.linalg.norm([3, 5, 1])), 2))Output
5.92
Learn the concept
New to this topic? Read the lesson, then come back.