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

Function zeros_like

dask/array/creation.py:177–229  ·  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="C", chunks=None, name=None, shape=None)

Source from the content-addressed store, hash-verified

175
176
177def zeros_like(a, dtype=None, order="C", chunks=None, name=None, shape=None):
178 """
179 Return an array of zeros with the same shape and type as a given array.
180
181 Parameters
182 ----------
183 a : array_like
184 The shape and data-type of `a` define these same attributes of
185 the returned array.
186 dtype : data-type, optional
187 Overrides the data type of the result.
188 order : {'C', 'F'}, optional
189 Whether to store multidimensional data in C- or Fortran-contiguous
190 (row- or column-wise) order in memory.
191 chunks : sequence of ints
192 The number of samples on each block. Note that the last block will have
193 fewer samples if ``len(array) % chunks != 0``.
194 name : str, optional
195 An optional keyname for the array. Defaults to hashing the input
196 keyword arguments.
197 shape : int or sequence of ints, optional.
198 Overrides the shape of the result.
199
200 Returns
201 -------
202 out : ndarray
203 Array of zeros with the same shape and type as `a`.
204
205 See Also
206 --------
207 ones_like : Return an array of ones with shape and type of input.
208 empty_like : Return an empty array with shape and type of input.
209 zeros : Return a new array setting values to zero.
210 ones : Return a new array setting values to one.
211 empty : Return a new uninitialized array.
212 """
213
214 a = asarray(a, name=False)
215 shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape)
216
217 # if shape is nan we cannot rely on regular zeros function, we use
218 # generic map_blocks.
219 if np.isnan(shape).any():
220 return a.map_blocks(partial(np.zeros_like, dtype=(dtype or a.dtype)))
221
222 return zeros(
223 shape,
224 dtype=(dtype or a.dtype),
225 order=order,
226 chunks=chunks,
227 name=name,
228 meta=a._meta,
229 )
230
231
232def full_like(a, fill_value, order="C", dtype=None, chunks=None, name=None, shape=None):

Callers

nothing calls this directly

Calls 4

asarrayFunction · 0.90
anyMethod · 0.45
map_blocksMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…