blosc2.prod#

blosc2.prod(ndarr: NDArray | NDField | C2Array | LazyExpr, axis: int | tuple[int] = None, dtype: dtype = None, keepdims: bool = False, **kwargs: dict) ndarray | NDArray | int | float | complex | bool#

Return the product of array elements over a given axis.

Parameters:
  • ndarr (NDArray or NDField or C2Array or LazyExpr) – The input array or expression.

  • axis (int or tuple of ints, optional) – Axis or axes along which a product is performed. The default, axis=None, will multiply all the elements of the input array. If axis is negative it counts from the last to the first axis.

  • dtype (np.dtype, optional) – The type of the returned array and of the accumulator in which the elements are multiplied. The dtype of ndarr is used by default unless ndarr has an integer dtype of less precision than the default platform integer.

  • keepdims (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

  • kwargs (dict, optional) – Keyword arguments that are supported by the empty() constructor.

Returns:

product_along_axis – The product of the elements along the axis.

Return type:

np.ndarray or NDArray or scalar

References

np.prod

Examples

>>> import numpy as np
>>> import blosc2
>>> # Create an instance of NDArray with some data
>>> array = np.array([[11, 22, 33], [4, 15, 36]])
>>> nd_array = blosc2.asarray(array)
>>> # Compute the product of all elements in the array
>>> prod_all = blosc2.prod(nd_array)
>>> print("Product of all elements in the array:", prod_all)
Product of all elements in the array: 17249760
>>> # Compute the product along axis 1 (rows)
>>> prod_axis1 = blosc2.prod(nd_array, axis=1)
>>> print("Product along axis 1:", prod_axis1)
Product along axis 1: [7986 2160]