跳到内容

压缩

从数组中移除单例维度。

参数

名称 类型 描述 默认值
x SparseArray

输入数组。

必需
axis inttuple[int, ...]

要移除的单例轴。默认情况下,所有单例轴都将被移除。

None

返回值

名称 类型 描述
output SparseArray

移除了单例维度的数组。

源代码位于 sparse/numba_backend/_common.py
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
@_support_numpy
def squeeze(x, /, axis=None):
    """Remove singleton dimensions from array.

    Parameters
    ----------
    x : SparseArray
        Input array.
    axis : int or tuple[int, ...], optional
        The singleton axes to remove. By default all singleton axes are removed.

    Returns
    -------
    output : SparseArray
        Array with singleton dimensions removed.
    """
    return x.squeeze(axis=axis)