To calculate the product of the elements in an array, utilize the prod() function.
Calculate the product of the elements in this array:
import numpy as np arr = np.array([1, 2, 3, 4]) x = np.prod(arr) print(x) |
Returns: 24, since 1×2×3×4=241 \times 2 \times 3 \times 4 = 24. |
Calculate the product of the elements in two arrays:
import numpy as np arr1 = np.array([1, 2, 3, 4]) arr2 = np.array([5, 6, 7, 8]) x = np.prod([arr1, arr2]) print(x) |