0
0
NumPydata~15 mins

Sorting along axes in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Sorting Along Axes with NumPy
📖 Scenario: Imagine you work in a small bakery. You have a list of daily sales for different types of bread over a week. You want to organize this data to see which days had the lowest to highest sales for each bread type and also which bread types sold the least to most on each day.
🎯 Goal: You will create a 2D NumPy array representing sales data, then sort the sales along rows and columns to better understand sales patterns.
📋 What You'll Learn
Create a 2D NumPy array called sales with exact values
Create a variable called axis_row set to 1
Create a variable called axis_col set to 0
Sort the sales array along rows using axis_row
Sort the sales array along columns using axis_col
Print both sorted arrays exactly as specified
💡 Why This Matters
🌍 Real World
Sorting sales data helps businesses quickly identify trends, like which products sell best on certain days or which days have the highest sales.
💼 Career
Data scientists and analysts often sort data along different axes to prepare it for reports, visualizations, or further analysis.
Progress0 / 4 steps
1
Create the sales data array
Create a 2D NumPy array called sales with these exact values: [[20, 35, 30], [25, 32, 34], [22, 30, 35]]
NumPy
Need a hint?

Use np.array() to create the 2D array with the exact nested list.

2
Set axis variables for sorting
Create a variable called axis_row and set it to 1. Then create a variable called axis_col and set it to 0.
NumPy
Need a hint?

Remember, axis=1 means sorting along rows, and axis=0 means sorting along columns.

3
Sort the sales array along rows and columns
Use np.sort() to sort the sales array along rows using axis_row and store it in sorted_rows. Then sort the sales array along columns using axis_col and store it in sorted_cols.
NumPy
Need a hint?

Use np.sort() with the axis parameter set to the axis variables.

4
Print the sorted arrays
Print the sorted_rows array first, then print the sorted_cols array.
NumPy
Need a hint?

Use two print() statements, one for each sorted array.