0
0
NumPydata~5 mins

Aggregation along specific axes in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does aggregation along a specific axis mean in numpy?
It means combining values in an array along a chosen direction (axis), like summing all rows or columns separately.
Click to reveal answer
beginner
How do you sum all elements in each column of a 2D numpy array?
Use np.sum(array, axis=0). Axis 0 means moving down rows, summing column-wise.
Click to reveal answer
beginner
What is the difference between axis=0 and axis=1 in numpy aggregation?
axis=0 aggregates down the rows (column-wise), axis=1 aggregates across columns (row-wise).
Click to reveal answer
beginner
How to find the maximum value in each row of a 2D numpy array?
Use np.max(array, axis=1). This finds the max value moving across columns for each row.
Click to reveal answer
beginner
Why is specifying the axis important in numpy aggregation functions?
Because it tells numpy which direction to combine values, affecting the shape and meaning of the result.
Click to reveal answer
What does np.sum(array, axis=0) do on a 2D array?
AReturns the original array
BSums each row separately
CSums all elements into one number
DSums each column separately
If you want to find the minimum value in each row, which axis should you use?
Aaxis=1
Baxis=2
Caxis=0
DNo axis needed
What shape will the result have after np.mean(array, axis=1) on a 2D array with shape (4,5)?
A(4,5)
B(5,)
C(4,)
D(1,5)
Which numpy function can you use to get the sum of all elements regardless of axis?
Anp.sum(array)
Bnp.sum(array, axis=0)
Cnp.sum(array, axis=1)
Dnp.sum(array, axis=2)
What happens if you use an invalid axis number in numpy aggregation?
AReturns zeros
BRaises an error
CIgnores the axis and sums all
DReturns the original array
Explain how aggregation along axis 0 and axis 1 differ in a 2D numpy array.
Think about summing columns vs summing rows.
You got /4 concepts.
    Describe why specifying the axis is important when using numpy aggregation functions.
    Consider what happens if you don't specify axis.
    You got /4 concepts.