prod

Contents

prod#

class saiunit.math.prod(x, axis=None, dtype=None, keepdims=False, initial=None, where=None)#

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 (Union[saiunit.Quantity, Array, ndarray, number, bool]) – Input data.

  • axis (Optional[int]) – 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 (Union[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 (Optional[bool]) – If True, the axes which are reduced are left in the result as dimensions with size one.

  • initial (Union[Array, ndarray, number, bool, saiunit.Quantity, None]) – The starting value for this product.

  • where (Union[Array, ndarray, number, bool, saiunit.Quantity, None]) – Elements to include in the product.

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:

Union[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