Complete the code to calculate the product of all elements in the array.
import numpy as np arr = np.array([1, 2, 3, 4]) result = np.[1](arr) print(result)
The np.prod() function calculates the product of all elements in the array.
Complete the code to calculate the product of elements along axis 0.
import numpy as np arr = np.array([[1, 2], [3, 4]]) result = np.prod(arr, axis=[1]) print(result)
Axis 0 means calculating the product down the rows (column-wise).
Fix the error in the code to correctly calculate the product of array elements.
import numpy as np arr = [1, 2, 3, 4] result = np.prod([1]) print(result)
np.prod() requires a numpy array or array-like. Converting list to numpy array ensures correct operation.
Complete the code to reshape the array and compute the product along axis 1.
import numpy as np arr = np.array([1,2,3,4,5,6]) reshaped = arr.[1]((2, 3)) result = np.[2](reshaped, axis=1) print(result)
np.sum() instead of np.prod()reshape()axis=0 instead of axis=1arr.reshape((2, 3)) reshapes to 2x3 array [[1,2,3],[4,5,6]], np.prod(..., axis=1) computes product per row: [6, 120].
Fill all three blanks to compute the geometric mean of the array.
import numpy as np arr = np.array([2, 4, 8]) geo_mean = (np.[1](arr)) ** ([2] / [3]) print(geo_mean)
np.sum(arr) instead of productnp.mean()/ np.sum(arr)Geometric mean = (product of elements)1/n, where n is the number of elements: (np.prod(arr)) ** (1 / len(arr)) = 4.0.