跳到内容

沿给定维度堆叠输入数组。

参数

名称 类型 描述 默认值
数组 可迭代对象[SparseArray]

要堆叠的输入数组。

必需
int

沿此轴堆叠输入数组。

0
compressed_axes 可迭代对象

如果返回 GCXS 数组,要压缩的轴。

None

返回值

类型 描述
SparseArray

输出的堆叠数组。

引发

类型 描述
ValueError

如果 `arrays` 的所有元素没有相同的填充值。

另请参阅

numpy.stack: NumPy 等效函数

源代码位于 sparse/numba_backend/_common.py
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
def stack(arrays, axis=0, compressed_axes=None):
    """
    Stack the input arrays along the given dimension.

    Parameters
    ----------
    arrays : Iterable[SparseArray]
        The input arrays to stack.
    axis : int, optional
        The axis along which to stack the input arrays.
    compressed_axes : iterable, optional
        The axes to compress if returning a GCXS array.

    Returns
    -------
    SparseArray
        The output stacked array.

    Raises
    ------
    ValueError
        If all elements of `arrays` don't have the same fill-value.

    See Also
    --------
    [`numpy.stack`][]: NumPy equivalent function
    """
    from ._compressed import GCXS

    if not builtins.all(isinstance(arr, GCXS) for arr in arrays):
        from ._coo import stack as coo_stack

        return coo_stack(arrays, axis)

    from ._compressed import stack as gcxs_stack

    return gcxs_stack(arrays, axis, compressed_axes)