count_nonzero

Contents

count_nonzero#

class brainunit.math.count_nonzero(a, axis=None, keepdims=None, **kwargs)#

Count the number of non-zero values in the input.

Units are stripped before counting.

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

  • axis (int | None) – Axis along which to count. Default counts over the whole array.

  • keepdims (bool | None) – If True, reduced axes are kept with size one.

Returns:

count – Number of non-zero values along the given axis.

Return type:

Array

Examples

>>> import saiunit as u
>>> import jax.numpy as jnp
>>> u.math.count_nonzero(jnp.array([0, 1, 0, 2, 3]))
Array(3, dtype=int32)