Recall & Review
beginner
What is a ufunc in NumPy?
A ufunc (universal function) is a function that operates element-wise on arrays, supporting fast vectorized operations in NumPy.
Click to reveal answer
beginner
What does the
reduce method of a ufunc do?The
reduce method applies the ufunc cumulatively to the elements of an array, reducing it to a single value along a specified axis.Click to reveal answer
intermediate
How does
accumulate differ from reduce in ufuncs?accumulate applies the ufunc cumulatively but returns all intermediate results as an array, showing the step-by-step accumulation.Click to reveal answer
beginner
Give a real-life example where
reduce is useful.Calculating the total sum of daily expenses over a month is like using
reduce to combine all values into one total.Click to reveal answer
beginner
What output do you get from
np.add.accumulate([1, 2, 3, 4])?You get
[1, 3, 6, 10], which shows the running total after adding each element step-by-step.Click to reveal answer
What does
np.multiply.reduce([2, 3, 4]) return?✗ Incorrect
reduce multiplies all elements: 2 * 3 * 4 = 24.Which ufunc method returns all intermediate results?
✗ Incorrect
accumulate returns the running results after each operation.What is the output of
np.add.reduce([5, 10, 15])?✗ Incorrect
reduce sums all elements: 5 + 10 + 15 = 30.If you want to see the sum after each addition step, which method do you use?
✗ Incorrect
Use
accumulate to get the running totals.Which of these is NOT a ufunc method?
✗ Incorrect
filter is not a ufunc method; the others are.Explain in your own words what the
reduce method does in NumPy ufuncs.Think about combining all elements step by step into one result.
You got /3 concepts.
Describe a situation where using
accumulate would be more helpful than reduce.When you want to see progress after each calculation.
You got /3 concepts.