0
0
NumPydata~15 mins

Why indexing matters in NumPy - See It in Action

Choose your learning style9 modes available
Why indexing matters
📖 Scenario: Imagine you have a list of daily temperatures for a week. You want to find the temperature on a specific day and also change the temperature for a day if needed.
🎯 Goal: You will create a NumPy array of temperatures, select a specific day's temperature using indexing, update a temperature, and then print the updated array.
📋 What You'll Learn
Create a NumPy array called temps with the exact values: 22, 24, 19, 23, 25, 20, 21
Create a variable called day_index and set it to 3
Use day_index to get the temperature for that day from temps and store it in selected_temp
Update the temperature at day_index in temps to 26
Print the updated temps array
💡 Why This Matters
🌍 Real World
Indexing is important when working with data like daily temperatures, sales numbers, or any list of values where you want to access or change specific items.
💼 Career
Data scientists often need to select and update data points efficiently using indexing in arrays or tables.
Progress0 / 4 steps
1
Create the temperature array
Create a NumPy array called temps with these exact values: 22, 24, 19, 23, 25, 20, 21
NumPy
Need a hint?

Use np.array([...]) to create the array with the exact numbers inside the brackets.

2
Set the day index
Create a variable called day_index and set it to 3
NumPy
Need a hint?

Just assign the number 3 to the variable day_index.

3
Select and update the temperature
Use day_index to get the temperature from temps and store it in selected_temp. Then update the temperature at day_index in temps to 26
NumPy
Need a hint?

Use temps[day_index] to get and set the value at that position.

4
Print the updated temperatures
Print the updated temps array
NumPy
Need a hint?

Use print(temps) to show the updated array.