nancumprod

Contents

nancumprod#

class saiunit.math.nancumprod(x, axis=None, dtype=None, **kwargs)#

Return the cumulative product of elements along a given axis treating NaNs as one.

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

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

  • axis (int | None) – Axis along which the cumulative product is computed. By default the input is flattened.

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

Returns:

cumprod – A new array holding the cumulative product with NaNs treated as one. If x carries a unit, the result is a Quantity.

Return type:

saiunit.Quantity | Array | ndarray | bool | number | bool | int | float | complex

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> q = u.math.array([2.0, jnp.nan, 3.0]) * u.meter
>>> u.math.nancumprod(q)