Recall & Review
beginner
What does the
np.sum() function do in NumPy?np.sum() adds up all the numbers in an array. It can add all elements or add along a specific direction (axis).
Click to reveal answer
beginner
What is the purpose of the
axis parameter in np.sum()?The axis parameter tells np.sum() which direction to add numbers along. For example, axis=0 adds down columns, axis=1 adds across rows.
Click to reveal answer
beginner
If you have a 2D array, what does
np.sum(array, axis=0) do?It adds the numbers down each column and returns a 1D array with sums for each column.
Click to reveal answer
beginner
What happens if you call
np.sum() without specifying the axis?It adds all the numbers in the whole array and returns a single number.
Click to reveal answer
beginner
Explain
axis=1 in np.sum() for a 2D array.axis=1 means add numbers across each row. The result is a 1D array with the sum of each row.
Click to reveal answer
What does
np.sum(array, axis=0) do for a 2D array?✗ Incorrect
axis=0 sums down columns in a 2D array.
If you want to add all elements in a NumPy array, what should you do?
✗ Incorrect
Without specifying axis, np.sum() adds all elements.
What does
axis=1 mean in np.sum() for a 2D array?✗ Incorrect
axis=1 sums across each row.
What type of result does
np.sum() return when you specify an axis?✗ Incorrect
Specifying axis returns sums along that direction as an array.
Which axis sums down the columns in a 2D NumPy array?
✗ Incorrect
axis=0 sums down columns in 2D arrays.
Describe how the
axis parameter changes the behavior of np.sum() when working with 2D arrays.Think about adding numbers in rows vs columns.
You got /4 concepts.
Explain what happens when you use
np.sum() on a 3D array with axis=1.Imagine stacking multiple 2D arrays and summing across the middle dimension.
You got /4 concepts.