0
0
NumPydata~15 mins

Fancy indexing with integer arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Fancy indexing with integer arrays
📖 Scenario: Imagine you have a list of daily temperatures for a week. You want to pick specific days to check the temperatures, but not in order. This is like picking favorite days to remember.
🎯 Goal: You will create a NumPy array of temperatures, then use fancy indexing with an integer array to select temperatures from specific days.
📋 What You'll Learn
Create a NumPy array called temps with these exact values: [22, 19, 24, 21, 20, 23, 18]
Create a NumPy array called days with these exact indices: [0, 3, 5]
Use fancy indexing with days to select temperatures from temps and store in selected_temps
Print the selected_temps array
💡 Why This Matters
🌍 Real World
Fancy indexing helps quickly pick specific data points from large datasets, like selecting certain days' temperatures from a weather dataset.
💼 Career
Data scientists often use fancy indexing to filter and analyze subsets of data efficiently without loops.
Progress0 / 4 steps
1
Create the temperature array
Import NumPy as np and create a NumPy array called temps with these exact values: [22, 19, 24, 21, 20, 23, 18]
NumPy
Need a hint?

Use import numpy as np first. Then create temps using np.array() with the exact list of numbers.

2
Create the days index array
Create a NumPy array called days with these exact indices: [0, 3, 5]
NumPy
Need a hint?

Use np.array() to create days with the exact indices.

3
Select temperatures using fancy indexing
Use fancy indexing with the days array to select temperatures from temps and store the result in a variable called selected_temps
NumPy
Need a hint?

Use temps[days] to pick the temperatures at the indices in days.

4
Print the selected temperatures
Print the selected_temps array to see the temperatures from the chosen days
NumPy
Need a hint?

Use print(selected_temps) to display the selected temperatures.