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 (
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 elements.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 (
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 ** nwherenis 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