0
0
NumPydata~15 mins

reshape() for changing dimensions in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Reshape Arrays with numpy.reshape()
📖 Scenario: Imagine you work in a bakery that tracks daily sales of different types of bread. The sales data is collected as a single list of numbers, but you want to organize it into a table showing sales per day and bread type.
🎯 Goal: You will create a numpy array from a list of sales numbers, then reshape it into a 2D array with rows as days and columns as bread types. Finally, you will print the reshaped array to see the organized sales data.
📋 What You'll Learn
Use numpy to create and reshape arrays
Create a 1D numpy array with exact sales data
Define a new shape as a tuple
Use numpy.reshape() to change the array dimensions
Print the reshaped array
💡 Why This Matters
🌍 Real World
Reshaping arrays is useful when you want to organize flat data into tables or grids, like sales data per day and product.
💼 Career
Data scientists often reshape data to prepare it for analysis or visualization, making this skill important for cleaning and structuring data.
Progress0 / 4 steps
1
Create the sales data array
Import numpy as np and create a 1D numpy array called sales with these exact values: 10, 15, 20, 25, 30, 35.
NumPy
Need a hint?

Use np.array() to create the array from the list of numbers.

2
Define the new shape for the array
Create a variable called new_shape and set it to the tuple (2, 3) to represent 2 days and 3 bread types.
NumPy
Need a hint?

A tuple is written with parentheses and commas, like (2, 3).

3
Reshape the sales array
Use np.reshape() with the sales array and new_shape to create a new array called reshaped_sales.
NumPy
Need a hint?

Call np.reshape() with the array first, then the shape tuple.

4
Print the reshaped sales array
Print the variable reshaped_sales to display the sales data organized by days and bread types.
NumPy
Need a hint?

Use print(reshaped_sales) to show the array.