跳到内容

zeros_like

返回一个具有与 a 相同形状和类型的零 SparseArray。

参数

名称 类型 描述 默认值
a array_like

结果的形状和数据类型将与 a 的形状和数据类型匹配。

必需
dtype 数据 - 类型

覆盖结果的数据类型。

None
format str

格式字符串。

None
compressed_axes iterable

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

必需

返回值

名称 类型 描述
out SparseArray

具有与 a 相同形状和类型的零数组。

示例

>>> x = np.ones((2, 3), dtype="i8")
>>> zeros_like(x).todense()
array([[0, 0, 0],
       [0, 0, 0]])
源代码位于 sparse/numba_backend/_common.py
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
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)