Python Practice › NumPy Programs › Program 77

Magnitude of a vector

EasyNumPy Programs · 77 of 100

Write a NumPy program to get the magnitude (length) of a vector.

Advertisement
Input
[3, 5, 1]
Output
5.92

Approach

  1. np.linalg.norm.

Solution

Python
import numpy as npprint(round(float(np.linalg.norm([3, 5, 1])), 2))
Output
5.92
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs