0
0
NumPydata~15 mins

2D array indexing (row, col) in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
2D Array Indexing with NumPy
📖 Scenario: You are working with a small grid of temperature readings from different sensors arranged in rows and columns. You want to access specific readings by their row and column positions.
🎯 Goal: Learn how to create a 2D NumPy array and access its elements using row and column indexes.
📋 What You'll Learn
Create a 2D NumPy array with exact values
Define variables for row and column indexes
Use these indexes to access the correct element in the array
Print the accessed element
💡 Why This Matters
🌍 Real World
Accessing specific data points in grids or tables is common in weather data, images, and spreadsheets.
💼 Career
Data scientists often need to extract and analyze specific values from multi-dimensional data arrays.
Progress0 / 4 steps
1
Create a 2D NumPy array
Import NumPy as np and create a 2D NumPy array called temps with these exact values: [[23, 25, 22], [21, 24, 20], [19, 22, 23]].
NumPy
Need a hint?

Use np.array() to create a 2D array from a list of lists.

2
Set row and column indexes
Create two variables called row and col. Set row to 1 and col to 2 to select the second row and third column.
NumPy
Need a hint?

Remember that Python uses zero-based indexing, so row 1 is the second row.

3
Access the element at the given row and column
Use the variables row and col to access the element in temps at that position. Store this value in a variable called selected_temp.
NumPy
Need a hint?

Use temps[row, col] to get the element at the specified row and column.

4
Print the selected temperature
Print the value stored in selected_temp.
NumPy
Need a hint?

Use print(selected_temp) to display the value.