0
0
NumPydata~15 mins

Why reshaping arrays matters in NumPy - See It in Action

Choose your learning style9 modes available
Why reshaping arrays matters
📖 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 by days and bread types to understand patterns better.
🎯 Goal: You will reshape a one-dimensional array of sales data into a two-dimensional array to see daily sales per bread type clearly.
📋 What You'll Learn
Create a NumPy array called sales with exactly 12 values representing sales.
Create a variable called days and set it to 4.
Use the reshape method on sales to create a new array called daily_sales with shape (days, 3).
Print the daily_sales array to see the reshaped data.
💡 Why This Matters
🌍 Real World
Reshaping arrays helps organize raw data into meaningful tables, like daily sales per product, making it easier to analyze and understand.
💼 Career
Data scientists often reshape data to prepare it for analysis, visualization, or machine learning models.
Progress0 / 4 steps
1
Create the sales data array
Create a NumPy array called sales with these exact values: [10, 15, 7, 12, 18, 9, 14, 20, 11, 13, 17, 8].
NumPy
Need a hint?

Use np.array([...]) with the exact numbers inside the brackets.

2
Set the number of days
Create a variable called days and set it to 4.
NumPy
Need a hint?

Just assign the number 4 to the variable days.

3
Reshape the sales array
Use the reshape method on sales to create a new array called daily_sales with shape (days, 3).
NumPy
Need a hint?

Use sales.reshape(days, 3) to reshape the array.

4
Print the reshaped sales data
Print the daily_sales array to see the sales organized by day and bread type.
NumPy
Need a hint?

Use print(daily_sales) to show the reshaped array.