nansum

Contents

nansum#

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

Return the sum of the array elements, ignoring NaNs.

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

  • axis (int | Sequence[int] | None) – Axis or axes along which the sum is computed. The default is to compute the sum of the flattened array.

  • dtype (str | type[Any] | dtype | SupportsDType | None) – The type of the returned array and of the accumulator in which the elements are summed. By default, the dtype of a is used. An exception is when a has an integer type with less precision than the platform (u)intp. In that case, the default will be either (u)int32 or (u)int64 depending on whether the platform is 32 or 64 bits. For inexact inputs, dtype must be inexact.

  • keepdims (bool) –

    If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original a.

    If the value is anything but the default, then keepdims will be passed through to the mean or sum methods of sub-classes of ndarray. If the sub-classes methods does not implement keepdims any exceptions will be raised.

  • initial (Array | ndarray | bool | number | bool | int | float | complex | saiunit.Quantity | None) – Starting value for the sum. See ~numpy.ufunc.reduce for details.

  • where (Array | ndarray | bool | number | bool | int | float | complex | None) – Elements to include in the sum. See ~numpy.ufunc.reduce for details.

Returns:

out – Quantity if x is a Quantity, else an array.

Return type:

saiunit.Quantity | Array

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> a = [1.0, jnp.nan, 3.0] * u.meter
>>> u.math.nansum(a)