jax.scipy.stats.mode#
- jax.scipy.stats.mode(a, axis=0, nan_policy='propagate', keepdims=False)[source]#
计算数组沿轴的众数(最常见的值)。
JAX
scipy.stats.mode()
的实现。- 参数:
- 返回:
数组元组,
(mode, count)
。mode
是模态值数组,count
是每个值在输入数组中出现的次数。- 返回类型:
ModeResult
示例
>>> x = jnp.array([2, 4, 1, 1, 3, 4, 4, 2, 3]) >>> mode, count = jax.scipy.stats.mode(x) >>> mode, count (Array(4, dtype=int32), Array(3, dtype=int32))
对于多维数组,
jax.scipy.stats.mode
沿axis=0
计算mode
和相应的count
>>> x1 = jnp.array([[1, 2, 1, 3, 2, 1], ... [3, 1, 3, 2, 1, 3], ... [1, 2, 2, 3, 1, 2]]) >>> mode, count = jax.scipy.stats.mode(x1) >>> mode, count (Array([1, 2, 1, 3, 1, 1], dtype=int32), Array([2, 2, 1, 2, 2, 1], dtype=int32))
如果
axis=1
,则将沿axis 1
计算mode
和count
。>>> mode, count = jax.scipy.stats.mode(x1, axis=1) >>> mode, count (Array([1, 3, 2], dtype=int32), Array([3, 3, 3], dtype=int32))
默认情况下,
jax.scipy.stats.mode
会降低结果的维度。要使维度与输入数组的维度相同,参数keepdims
必须设置为True
。>>> mode, count = jax.scipy.stats.mode(x1, axis=1, keepdims=True) >>> mode, count (Array([[1], [3], [2]], dtype=int32), Array([[3], [3], [3]], dtype=int32))