0
0
NumPydata~15 mins

np.linalg.norm() for vector norms in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Calculate Vector Norms Using np.linalg.norm()
📖 Scenario: Imagine you are working with a delivery company that tracks the movement of packages in 3D space. You want to calculate how far each package has moved from the origin point (0,0,0) using vector norms.
🎯 Goal: You will create a list of 3D vectors representing package movements, set a norm order, calculate the norms of each vector using np.linalg.norm(), and print the results.
📋 What You'll Learn
Create a list of 3D vectors using numpy arrays with exact values
Set a variable for the norm order (e.g., 2 for Euclidean norm)
Use a for loop to calculate the norm of each vector using np.linalg.norm() with the given order
Print the list of calculated norms
💡 Why This Matters
🌍 Real World
Calculating vector norms is useful in physics to find distances or magnitudes, in machine learning to measure errors or distances between points, and in computer graphics to calculate lengths and directions.
💼 Career
Data scientists and engineers often use vector norms to preprocess data, evaluate models, and analyze spatial data.
Progress0 / 4 steps
1
Create a list of 3D vectors
Create a list called vectors containing these three numpy arrays exactly: np.array([3, 4, 0]), np.array([1, 2, 2]), and np.array([0, 0, 5]).
NumPy
Need a hint?

Use np.array() to create each vector and put them inside a list called vectors.

2
Set the norm order
Create a variable called norm_order and set it to 2 to calculate the Euclidean norm.
NumPy
Need a hint?

Set norm_order to 2 for the Euclidean norm.

3
Calculate norms of each vector
Create an empty list called norms. Use a for loop with variable vec to iterate over vectors. Inside the loop, calculate the norm of vec using np.linalg.norm(vec, ord=norm_order) and append the result to norms.
NumPy
Need a hint?

Use a for loop to go through each vector and calculate its norm with np.linalg.norm(). Append each norm to the norms list.

4
Print the list of norms
Write a print statement to display the norms list.
NumPy
Need a hint?

Use print(norms) to show the list of calculated norms.