Bird
0
0

You have a nested list representing monthly sales for 3 stores over 4 months:

hard📝 Application Q8 of 15
NumPy - Creating Arrays
You have a nested list representing monthly sales for 3 stores over 4 months:
sales = [[100, 120, 130, 140], [90, 110, 115, 130], [80, 105, 125, 135]]

How can you create a numpy array and find the average sales per month across all stores?
Aarr = np.array(sales); avg = arr.mean(axis=1)
Barr = np.array(sales); avg = arr.sum(axis=0)
Carr = np.array(sales); avg = arr.mean(axis=0)
Darr = np.array(sales); avg = arr.sum(axis=1)
Step-by-Step Solution
Solution:
  1. Step 1: Convert list to numpy array

    Use np.array(sales) to create a 2D array with shape (3,4).
  2. Step 2: Calculate average per month

    Use mean(axis=0) to average over stores (rows) for each month (columns).
  3. Final Answer:

    arr = np.array(sales); avg = arr.mean(axis=0) -> Option C
  4. Quick Check:

    axis=0 averages columns (months) [OK]
Quick Trick: Use mean(axis=0) to average columns in 2D array [OK]
Common Mistakes:
  • Using axis=1 averages rows, not months
  • Using sum instead of mean
  • Not converting list to array first

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes