jax.numpy.min#

jax.numpy.min(a, axis=None, out=None, keepdims=False, initial=None, where=None)[source]#

Return the minimum of array elements along a given axis.

JAX implementation of numpy.min().

Parameters:
  • a (ArrayLike) – Input array.

  • axis (Axis | None) – int or array, default=None. Axis along which the minimum to be computed. If None, the minimum is computed along all the axes.

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

  • initial (ArrayLike | None | None) – int or array, Default=None. Initial value for the minimum.

  • where (ArrayLike | None | None) – int or array, default=None. The elements to be used in the minimum. Array should be broadcast compatible to the input. initial must be specified when where is used.

  • out (None | None) – Unused by JAX.

Returns:

An array of minimum values along the given axis.

Return type:

Array

See also

Examples

By default, the minimum is computed along all the axes.

>>> x = jnp.array([[2, 5, 1, 6],
...                [3, -7, -2, 4],
...                [8, -4, 1, -3]])
>>> jnp.min(x)
Array(-7, dtype=int32)

If axis=1, the minimum is computed along axis 1.

>>> jnp.min(x, axis=1)
Array([ 1, -7, -4], dtype=int32)

If keepdims=True, ndim of the output will be same of that of the input.

>>> jnp.min(x, axis=1, keepdims=True)
Array([[ 1],
       [-7],
       [-4]], dtype=int32)

To include only specific elements in computing the minimum, you can use where. where can either have same dimension as input.

>>> where=jnp.array([[1, 0, 1, 0],
...                  [0, 0, 1, 1],
...                  [1, 1, 1, 0]], dtype=bool)
>>> jnp.min(x, axis=1, keepdims=True, initial=0, where=where)
Array([[ 0],
       [-2],
       [-4]], dtype=int32)

or must be broadcast compatible with input.

>>> where = jnp.array([[False],
...                    [False],
...                    [False]])
>>> jnp.min(x, axis=0, keepdims=True, initial=0, where=where)
Array([[0, 0, 0, 0]], dtype=int32)