跳到内容

min

计算输入数组 x 的最小值。

参数

名称 类型 描述 默认值
x

输入数组。应具有实数值数据类型。

必需
axis

计算最小值的轴或多个轴。默认情况下,最小值必须在整个数组上计算。如果为整数元组,则最小值必须在多个轴上计算。默认值:None

None
keepdims

如果为 True,则将缩减后的轴(维度)作为单例维度包含在结果中。因此,结果必须与输入数组兼容。否则,如果为 False,则不将缩减后的轴(维度)包含在结果中。默认值:False

False

返回值

名称 类型 描述
out 数组

如果最小值是在整个数组上计算的,则返回一个包含最小值的零维数组。否则,返回一个包含最小值的非零维数组。返回的数组必须与 x 具有相同的数据类型。

特殊情况

对于浮点操作数,如果 x_iNaN,则最小值为 NaN(即 NaN 值会传播)。

示例

>>> a = sparse.COO.from_numpy(np.array([[0, -1], [-2, 0]]))
>>> o = sparse.min(a, axis=1)
>>> o.todense()
array([-1, -2])
源代码位于 sparse/numba_backend/_common.py
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
def min(x, /, *, axis=None, keepdims=False):
    """
    Calculates the minimum value of the input array ``x``.

    Parameters
    ----------
    x: array
        input array. Should have a real-valued data type.
    axis: Optional[Union[int, Tuple[int, ...]]]
        axis or axes along which minimum values are computed.
        By default, the minimum value must be computed over the entire array.
        If a tuple of integers, minimum values must be computed over multiple axes. Default: ``None``.
    keepdims: bool
        If ``True``, the reduced axes (dimensions) are included in the result as singleton dimensions.
        Accordingly, the result must be compatible with the input array.
        Otherwise, if ``False``, the reduced axes (dimensions) are not be included in the result. Default: ``False``.

    Returns
    -------
    out: array
        if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value.
        Otherwise, a non-zero-dimensional array containing the minimum values.
        The returned array must have the same data type as ``x``.

    Special Cases
    -------------
    For floating-point operands, if ``x_i`` is ``NaN``, the minimum value is ``NaN`` (i.e., ``NaN`` values propagate).

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, -1], [-2, 0]]))
    >>> o = sparse.min(a, axis=1)
    >>> o.todense()
    array([-1, -2])
    """
    return x.min(axis=axis, keepdims=keepdims)