Source Code:
(back to article)
import numpy as np # Initialize an array arr = np.array([1, 2, 3]) # Calculate the magnitude of the vector magnitude = np.linalg.norm(arr) # Normalize the array by dividing by the magnitude unit_vec = arr / magnitude print(unit_vec)
Result:
Report an issue