Numpy.prod() in Python (original) (raw)

Last Updated : 5 Jun, 2026

numpy.prod() is used to calculate the product of array elements. It can multiply all elements of an array or multiply elements along a specific axis in multi-dimensional arrays. It is commonly used in numerical computing when we need the multiplication result of multiple values stored in a NumPy array.

**Example: This example multiplies all elements of a NumPy array using np.prod().

Python `

import numpy as np arr = [1, 2, 3, 4] res = np.prod(arr) print(res)

`

**Explanation: np.prod(arr) multiplies all elements of arr: 1 × 2 × 3 × 4 = 24.

Syntax

numpy.prod(a, axis=None, dtype=None, out=None, keepdims=False)

**Parameters:

Examples

**Example 1: This example finds the product of all elements in a 1D array using np.prod().

Python `

import numpy as np arr = np.array([2, 3, 4]) res = np.prod(arr) print(res)

`

**Explanation: np.prod(arr) multiplies all array elements: 2 × 3 × 4 = 24.

**Example 2: This example calculates the product of elements row-wise in a 2D array using axis=1.

Python `

import numpy as np arr = np.array([[1, 2], [3, 4]]) res = np.prod(arr, axis=1) print(res)

`

**Explanation: axis=1 calculates the product across each row:

**Example 3: This example shows the result when np.prod() is applied to an empty array.

Python `

import numpy as np arr = [] res = np.prod(arr) print(res)

`

**Explanation: For an empty array, np.prod() returns 1.0, which is the neutral value for multiplication.