prod

Contents

prod#

class brainunit.math.prod(x, axis=None, dtype=None, keepdims=False, initial=None, where=None, promote_integers=True, **kwargs)#

Return the product of array elements over a given axis.

When the input is a Quantity, the resulting unit is the input unit raised to the power equal to the number of elements along the reduced axis.

Parameters:
  • x (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Input data.

  • axis (int | None) – Axis or axes along which a product is performed. The default, axis=None, will calculate the product of all the elements in the input array.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – The type of the returned array, as well as of the accumulator in which the elements are multiplied.

  • keepdims (bool | None) – If True, the axes which are reduced are left in the result as dimensions with size one.

  • initial (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – The starting value for this product.

  • where (saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex) – Elements to include in the product.

  • promote_integers (bool) – Whether to promote integer dtypes to the default platform integer.

Returns:

product_along_axis – An array shaped as x but with the specified axis removed. If x carries a unit, the result is a Quantity whose unit is x.unit ** n where n is the number of elements reduced.

Return type:

saiunit.Quantity | Array

Examples

>>> import saiunit as u
>>> q = u.math.array([2.0, 3.0]) * u.meter
>>> u.math.prod(q)  # product is 6.0, unit is meter ** 2