A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.jax.dev/en/latest/_autosummary/jax.numpy.count_nonzero.html below:

jax.numpy.count_nonzero — JAX documentation

jax.numpy.count_nonzero#
jax.numpy.count_nonzero(a, axis=None, keepdims=False)[source]#

Return the number of nonzero elements along a given axis.

JAX implementation of numpy.count_nonzero().

Parameters:
  • a (ArrayLike) – input array.

  • axis (Axis) – optional, int or sequence of ints, default=None. Axis along which the number of nonzeros are counted. If None, counts within the flattened array.

  • keepdims (bool) – bool, default=False. If true, reduced axes are left in the result with size 1.

Returns:

An array with number of nonzeros elements along specified axis of the input.

Return type:

Array

Examples

By default, jnp.count_nonzero counts the nonzero values along all axes.

>>> x = jnp.array([[1, 0, 0, 0],
...                [0, 0, 1, 0],
...                [1, 1, 1, 0]])
>>> jnp.count_nonzero(x)
Array(5, dtype=int32)

If axis=1, counts along axis 1.

>>> jnp.count_nonzero(x, axis=1)
Array([1, 1, 3], dtype=int32)

To preserve the dimensions of input, you can set keepdims=True.

>>> jnp.count_nonzero(x, axis=1, keepdims=True)
Array([[1],
       [1],
       [3]], dtype=int32)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4