0
0
NumPydata~15 mins

np.argmin() and np.argmax() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Finding Minimum and Maximum Indices with np.argmin() and np.argmax()
📖 Scenario: Imagine you have a list of daily temperatures for a week. You want to find which day was the coldest and which day was the hottest.
🎯 Goal: You will create a NumPy array of temperatures, set a threshold temperature, find the indices of the coldest and hottest days using np.argmin() and np.argmax(), and then print those indices.
📋 What You'll Learn
Create a NumPy array called temperatures with exact values: [22, 19, 25, 21, 20, 23, 18]
Create a variable called threshold and set it to 20
Use np.argmin(temperatures) to find the index of the coldest day and store it in coldest_day
Use np.argmax(temperatures) to find the index of the hottest day and store it in hottest_day
Print the values of coldest_day and hottest_day
💡 Why This Matters
🌍 Real World
Finding minimum and maximum values and their positions is common in weather data analysis, stock prices, and many other fields.
💼 Career
Data scientists often need to quickly identify key points in data sets, such as the lowest or highest values, to make decisions or create reports.
Progress0 / 4 steps
1
Create the temperatures array
Import NumPy as np and create a NumPy array called temperatures with these exact values: [22, 19, 25, 21, 20, 23, 18]
NumPy
Need a hint?

Use import numpy as np to import NumPy. Then use np.array([...]) to create the array.

2
Set the threshold temperature
Create a variable called threshold and set it to the integer 20
NumPy
Need a hint?

Just assign the number 20 to a variable named threshold.

3
Find indices of coldest and hottest days
Use np.argmin(temperatures) to find the index of the coldest day and store it in coldest_day. Use np.argmax(temperatures) to find the index of the hottest day and store it in hottest_day
NumPy
Need a hint?

Use np.argmin() and np.argmax() functions on the temperatures array.

4
Print the results
Print the values of coldest_day and hottest_day on separate lines
NumPy
Need a hint?

Use two print() statements, one for each variable.