w3resource logo


Python Exercises

Python NumPy: Get the magnitude of a vector in numpy

Python NumPy: Array Object Exercise-93 with Solution

Write a Python program to get the magnitude of a vector in numpy.

Sample Solution:-

Python Code:

import numpy as np
x = np.array([1,2,3,4,5])
print("Original array:")
print("Magnitude of the vector:")

Sample Output:

Original array:                                                        
[1 2 3 4 5]                                                            
Magnitude of the vector:                                               

Python Code Editor:

Improve this sample solution and post your code through Disqus