jax.scipy.stats.mode#

jax.scipy.stats.mode(a, axis=0, nan_policy='propagate', keepdims=False)[source]#

Return an array of the modal (most common) value in the passed array.

LAX-backend implementation of scipy.stats._stats_py.mode().

Currently the only supported nan_policy is ‘propagate’

Original docstring below.

If there is more than one such value, only one is returned. The bin-count for the modal bins is also returned.

Parameters:
  • a (array_like) – n-dimensional array of which to find mode(s).

  • axis (int or None, optional) – Axis along which to operate. Default is 0. If None, compute over the whole array a.

  • nan_policy ({'propagate', 'raise', 'omit'}, optional) –

    Defines how to handle when input contains nan. The following options are available (default is ‘propagate’):

    • ’propagate’: treats nan as it would treat any other value

    • ’raise’: throws an error

    • ’omit’: performs the calculations ignoring nan values

  • keepdims (bool, optional) –

    If set to False, the axis over which the statistic is taken is consumed (eliminated from the output array) like other reduction functions (e.g. skew, kurtosis). If set to True, the axis is retained with size one, and the result will broadcast correctly against the input array. The default, None, is undefined legacy behavior retained for backward compatibility.

    Warning

    Unlike other reduction functions (e.g. skew, kurtosis), the default behavior of mode usually retains the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of keepdims will become False, the axis over which the statistic is taken will be eliminated, and the value None will no longer be accepted.

Return type:

ModeResult

Returns:

  • mode (ndarray) – Array of modal values.

  • count (ndarray) – Array of counts for each mode.