Skip to content

zeros_like

Return a SparseArray of zeros with the same shape and type as a.

Parameters:

Name Type Description Default
a array_like

The shape and data-type of the result will match those of a.

required
dtype data - type

Overrides the data type of the result.

None
format str

A format string.

None
compressed_axes iterable

The axes to compress if returning a GCXS array.

required

Returns:

Name Type Description
out SparseArray

Array of zeros with the same shape and type as a.

Examples:

>>> x = np.ones((2, 3), dtype="i8")
>>> zeros_like(x).todense()
array([[0, 0, 0],
       [0, 0, 0]])
Source code in sparse/numba_backend/_common.py
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
def zeros_like(a, dtype=None, shape=None, format=None, *, device=None, **kwargs):
    """Return a SparseArray of zeros with the same shape and type as ``a``.

    Parameters
    ----------
    a : array_like
        The shape and data-type of the result will match those of `a`.
    dtype : data-type, optional
        Overrides the data type of the result.
    format : str, optional
        A format string.
    compressed_axes : iterable, optional
        The axes to compress if returning a GCXS array.

    Returns
    -------
    out : SparseArray
        Array of zeros with the same shape and type as `a`.

    Examples
    --------
    >>> x = np.ones((2, 3), dtype="i8")
    >>> zeros_like(x).todense()  # doctest: +NORMALIZE_WHITESPACE
    array([[0, 0, 0],
           [0, 0, 0]])
    """
    return full_like(a, fill_value=0, dtype=dtype, shape=shape, format=format, device=device, **kwargs)