nanprod

Contents

nanprod#

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

Return the product of array elements over a given axis treating NaNs as one.

Behaves like prod() but treats NaN values as one, so they do not affect the product.

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 elements.

  • 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) – 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.

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:

ndarray or Quantity

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> q = u.math.array([2.0, jnp.nan, 3.0]) * u.meter
>>> u.math.nanprod(q)  # NaN treated as 1, result is 6.0