0
0
NumPydata~30 mins

ndarray as the core data structure in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
ndarray as the core data structure
📖 Scenario: You are working with temperature data collected from three cities over four days. The data is organized in a table format, where each row represents a city and each column represents a day.
🎯 Goal: You will create a NumPy ndarray to hold this temperature data, set up a variable for the number of days, extract temperatures for a specific city, and finally print the extracted data.
📋 What You'll Learn
Use NumPy to create an ndarray with exact temperature values
Create a variable to store the number of days
Extract temperatures for the city 'CityB' using ndarray indexing
Print the extracted temperatures
💡 Why This Matters
🌍 Real World
Scientists and analysts often use ndarrays to store and analyze data collected over time or across different locations.
💼 Career
Understanding how to use ndarrays is essential for data scientists and analysts working with numerical data in Python.
Progress0 / 4 steps
1
Create the temperature data ndarray
Import NumPy as np and create a 2D ndarray called temperatures with these exact values: first row [22, 21, 23, 22], second row [19, 20, 21, 20], third row [25, 26, 27, 26].
NumPy
Need a hint?

Use np.array() to create the ndarray with the exact nested list of values.

2
Set the number of days variable
Create a variable called num_days and set it to the number of columns in the temperatures ndarray.
NumPy
Need a hint?

Use the shape attribute of the ndarray to get the number of columns.

3
Extract temperatures for CityB
Create a variable called cityb_temps that extracts the second row (index 1) from the temperatures ndarray.
NumPy
Need a hint?

Use indexing with [1] to get the second row from the ndarray.

4
Print the extracted temperatures
Print the variable cityb_temps to display the temperatures for CityB.
NumPy
Need a hint?

Use print(cityb_temps) to display the array.