Skip to content

stack

Stack the input arrays along the given dimension.

Parameters:

Name Type Description Default
arrays Iterable[SparseArray]

The input arrays to stack.

required
axis int

The axis along which to stack the input arrays.

0
compressed_axes iterable

The axes to compress if returning a GCXS array.

None

Returns:

Type Description
SparseArray

The output stacked array.

Raises:

Type Description
ValueError

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

See Also

numpy.stack: NumPy equivalent function

Source code in sparse/numba_backend/_common.py
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
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)