Instagram
youtube
Facebook
Twitter

Compute Norm of a NumPy Array

A Compute Norm of a NumPy Array?
Code Explanation:
Library Import:
numpy is imported as np to use numerical and linear algebra functions.
Array Creation: A 1D NumPy array arr is created with values [3, 4].
Compute Norm: np.linalg.norm(arr) calculates the Euclidean norm (also called magnitude or length) of the vector.
Norm Formula: For vector [3, 4], the norm is computed as √(3² + 4²) = √(9 + 16) = √25 = 5.
Store Result: The computed norm value is stored in the variable norm.
Display Output: print(norm) prints the length (norm) of the vector.

 

Program:

import numpy as np

arr = np.array([3, 4])

norm = np.linalg.norm(arr)

print(norm)