跳到内容

拼接

沿给定维度拼接输入数组。

参数

名称 类型 描述 默认值
数组 Iterable[SparseArray]

要拼接的输入数组。

必需
int

沿此轴拼接输入数组。默认值为零。

0
compressed_axes iterable

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

None

返回值

类型 描述
SparseArray

输出的拼接数组。

引发

类型 描述
ValueError

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

另请参阅

numpy.concatenate : NumPy 等效函数

源代码位于 sparse/numba_backend/_common.py
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
def concatenate(arrays, axis=0, compressed_axes=None):
    """
    Concatenate the input arrays along the given dimension.

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

    Returns
    -------
    SparseArray
        The output concatenated array.

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

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

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

        return coo_concat(arrays, axis)

    from ._compressed import concatenate as gcxs_concat

    return gcxs_concat(arrays, axis, compressed_axes)