Challenge - 5 Problems
np.prod() Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of np.prod() on a 1D array
What is the output of the following code?
import numpy as np arr = np.array([2, 3, 4]) result = np.prod(arr) print(result)
NumPy
import numpy as np arr = np.array([2, 3, 4]) result = np.prod(arr) print(result)
Attempts:
2 left
💡 Hint
np.prod() multiplies all elements in the array.
✗ Incorrect
np.prod() multiplies all elements: 2 * 3 * 4 = 24.
❓ data_output
intermediate2:00remaining
Product along axis in 2D array
Given the 2D array below, what is the output of np.prod(arr, axis=0)?
import numpy as np arr = np.array([[1, 2], [3, 4]]) result = np.prod(arr, axis=0) print(result)
NumPy
import numpy as np arr = np.array([[1, 2], [3, 4]]) result = np.prod(arr, axis=0) print(result)
Attempts:
2 left
💡 Hint
Multiplying elements down each column.
✗ Incorrect
Product along axis=0 multiplies elements in each column: [1*3, 2*4] = [3, 8].
❓ Predict Output
advanced2:00remaining
Effect of dtype parameter in np.prod()
What is the output of this code?
import numpy as np arr = np.array([1000, 2000, 3000], dtype=np.int16) result = np.prod(arr, dtype=np.int64) print(result)
NumPy
import numpy as np arr = np.array([1000, 2000, 3000], dtype=np.int16) result = np.prod(arr, dtype=np.int64) print(result)
Attempts:
2 left
💡 Hint
dtype controls the type used for multiplication to avoid overflow.
✗ Incorrect
Using dtype=np.int64 avoids overflow and calculates 1000*2000*3000 = 6000000000.
❓ data_output
advanced2:00remaining
Product of an empty array
What is the output of np.prod() when applied to an empty array?
import numpy as np arr = np.array([]) result = np.prod(arr) print(result)
NumPy
import numpy as np arr = np.array([]) result = np.prod(arr) print(result)
Attempts:
2 left
💡 Hint
Think about the identity value for multiplication.
✗ Incorrect
The product of an empty array is 1.0 by definition (multiplicative identity).
❓ visualization
expert3:00remaining
Visualizing product along different axes
You have this 3D array:
Which option correctly describes the shape of the output when applying np.prod(arr, axis=1)?
import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
Which option correctly describes the shape of the output when applying np.prod(arr, axis=1)?
NumPy
import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) result = np.prod(arr, axis=1) print(result) print(result.shape)
Attempts:
2 left
💡 Hint
Multiplying elements along axis 1 means multiplying rows inside each 2D slice.
✗ Incorrect
Axis=1 means multiply elements in each 2D slice along the second dimension: [[1*3, 2*4], [5*7, 6*8]] = [[3,8],[35,48]] with shape (2,2).