MCPcopy Index your code
hub / github.com/numpy/numpy / zeros_like

Function zeros_like

numpy/_core/numeric.py:98–167  ·  view source on GitHub ↗

Return an array of zeros with the same shape and type as a given array. Parameters ---------- a : array_like The shape and data-type of `a` define these same attributes of the returned array. dtype : data-type, optional Overrides the data type of the res

(
    a, dtype=None, order='K', subok=True, shape=None, *, device=None
)

Source from the content-addressed store, hash-verified

96
97@array_function_dispatch(_zeros_like_dispatcher)
98def zeros_like(
99 a, dtype=None, order='K', subok=True, shape=None, *, device=None
100):
101 """
102 Return an array of zeros with the same shape and type as a given array.
103
104 Parameters
105 ----------
106 a : array_like
107 The shape and data-type of `a` define these same attributes of
108 the returned array.
109 dtype : data-type, optional
110 Overrides the data type of the result.
111 order : {'C', 'F', 'A', or 'K'}, optional
112 Overrides the memory layout of the result. 'C' means C-order,
113 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
114 'C' otherwise. 'K' means match the layout of `a` as closely
115 as possible.
116 subok : bool, optional.
117 If True, then the newly created array will use the sub-class
118 type of `a`, otherwise it will be a base-class array. Defaults
119 to True.
120 shape : int or sequence of ints, optional.
121 Overrides the shape of the result. If order='K' and the number of
122 dimensions is unchanged, will try to keep order, otherwise,
123 order='C' is implied.
124 device : str, optional
125 The device on which to place the created array. Default: None.
126 For Array-API interoperability only, so must be ``"cpu"`` if passed.
127
128 .. versionadded:: 2.0.0
129
130 Returns
131 -------
132 out : ndarray
133 Array of zeros with the same shape and type as `a`.
134
135 See Also
136 --------
137 empty_like : Return an empty array with shape and type of input.
138 ones_like : Return an array of ones with shape and type of input.
139 full_like : Return a new array with shape of input filled with value.
140 zeros : Return a new array setting values to zero.
141
142 Examples
143 --------
144 >>> import numpy as np
145 >>> x = np.arange(6)
146 >>> x = x.reshape((2, 3))
147 >>> x
148 array([[0, 1, 2],
149 [3, 4, 5]])
150 >>> np.zeros_like(x)
151 array([[0, 0, 0],
152 [0, 0, 0]])
153
154 >>> y = np.arange(3, dtype=np.float64)
155 >>> y

Callers 5

piecewiseFunction · 0.90
apply_along_axisFunction · 0.90
test_zerosMethod · 0.90
test_fft_out_argumentMethod · 0.85

Calls 2

empty_likeFunction · 0.85
zerosFunction · 0.85

Tested by 3

test_zerosMethod · 0.72
test_fft_out_argumentMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…