0
0
NumPydata~15 mins

Array attributes (shape, dtype, ndim, size) in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Explore NumPy Array Attributes
📖 Scenario: You are working with data collected from a small weather station. The data is stored in arrays representing temperature readings over several days.
🎯 Goal: Learn how to create a NumPy array and explore its basic attributes: shape, dtype, ndim, and size.
📋 What You'll Learn
Create a NumPy array with specific temperature data
Create a variable to hold the array
Access and print the array's shape, dtype, ndim, and size attributes
💡 Why This Matters
🌍 Real World
Data scientists often check array attributes to understand the data's structure before processing it.
💼 Career
Knowing array attributes is essential for data cleaning, transformation, and ensuring compatibility with machine learning models.
Progress0 / 4 steps
1
Create a NumPy array with temperature data
Import the NumPy library as np and create a NumPy array called temps with these exact values: [[22, 21, 23], [20, 19, 18], [25, 24, 26]].
NumPy
Need a hint?

Use np.array() to create the array with the nested list of temperatures.

2
Create a variable to hold the array's shape
Create a variable called shape and set it to the shape attribute of the temps array.
NumPy
Need a hint?

Use temps.shape to get the shape of the array.

3
Create variables for dtype, ndim, and size
Create three variables: dtype set to temps.dtype, ndim set to temps.ndim, and size set to temps.size.
NumPy
Need a hint?

Access each attribute directly from the temps array.

4
Print the array attributes
Print the variables shape, dtype, ndim, and size each on a separate line in this exact order.
NumPy
Need a hint?

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