Bird
0
0

Given a 2D NumPy array data representing daily temperatures for a week (rows = days, columns = cities), how would you find the highest temperature recorded in each city?

hard📝 Application Q15 of 15
NumPy - Aggregation Functions
Given a 2D NumPy array data representing daily temperatures for a week (rows = days, columns = cities), how would you find the highest temperature recorded in each city?
Anp.max(data, axis=1)
Bnp.min(data, axis=1)
Cnp.min(data, axis=0)
Dnp.max(data, axis=0)
Step-by-Step Solution
Solution:
  1. Step 1: Understand data layout

    Rows represent days, columns represent cities. To find max per city, we want max down each column.
  2. Step 2: Use axis=0 for column-wise operation

    Using np.max(data, axis=0) finds the maximum temperature for each city across all days.
  3. Final Answer:

    np.max(data, axis=0) -> Option D
  4. Quick Check:

    Max per city = np.max(data, axis=0) [OK]
Quick Trick: axis=0 aggregates down columns (cities) [OK]
Common Mistakes:
  • Using axis=1 to find max per city
  • Using np.min() instead of np.max()
  • Confusing rows and columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes