Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

ufunc Products

Products

To calculate the product of the elements in an array, utilize the prod() function.

Example

Calculate the product of the elements in this array:

import numpy as np

arr = np.array([1234])

x = np.prod(arr)

print(x)
Returns: 24, since 1×2×3×4=241 \times 2 \times 3 \times 4 = 24.

Example

Calculate the product of the elements in two arrays:

import numpy as np

arr1 = np.array([1234])
arr2 = np.array([5678])

x = np.prod([arr1, arr2])

print(x)