0
0
NumPydata~30 mins

Multi-dimensional fancy indexing in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Multi-dimensional Fancy Indexing with NumPy
📖 Scenario: You work at a sports analytics company. You have a 2D array representing scores of 4 players in 5 games. You want to select specific scores using multi-dimensional fancy indexing to analyze performance.
🎯 Goal: Learn how to use multi-dimensional fancy indexing in NumPy to select specific elements from a 2D array.
📋 What You'll Learn
Create a 2D NumPy array called scores with exact values
Create two 1D NumPy arrays called row_indices and col_indices for indexing
Use multi-dimensional fancy indexing with row_indices and col_indices to select elements from scores
Print the selected elements
💡 Why This Matters
🌍 Real World
Selecting specific data points from multi-dimensional datasets is common in sports analytics, image processing, and scientific computing.
💼 Career
Data scientists and analysts often use fancy indexing to efficiently extract and analyze subsets of data from large arrays.
Progress0 / 4 steps
1
Create the scores array
Import NumPy as np and create a 2D NumPy array called scores with these exact values: [[10, 20, 30, 40, 50], [15, 25, 35, 45, 55], [12, 22, 32, 42, 52], [17, 27, 37, 47, 57]]
NumPy
Need a hint?

Use np.array() to create the 2D array with the exact nested lists.

2
Create row and column index arrays
Create two 1D NumPy arrays called row_indices and col_indices with these exact values: row_indices = np.array([0, 1, 2, 3]) and col_indices = np.array([4, 3, 2, 1])
NumPy
Need a hint?

Use np.array() to create the index arrays with the exact values.

3
Select elements using multi-dimensional fancy indexing
Use multi-dimensional fancy indexing with row_indices and col_indices on scores to create a new array called selected_scores that contains the elements at those positions.
NumPy
Need a hint?

Use scores[row_indices, col_indices] to select elements at matching pairs of indices.

4
Print the selected scores
Print the selected_scores array to display the selected elements.
NumPy
Need a hint?

Use print(selected_scores) to display the array.