NumPy: Get the magnitude of a vector in numpy
NumPy: Array Object Exercise-93 with Solution
Write a NumPy program to get the magnitude of a vector in numpy.
import numpy as np x = np.array([1,2,3,4,5]) print("Original array:") print(x) print("Magnitude of the vector:") print(np.linalg.norm(x))
Original array: [1 2 3 4 5] Magnitude of the vector: 7.4161984871
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?