MCPcopy
hub / github.com/dask/dask / empty_like

Function empty_like

dask/array/_array_expr/_creation.py:289–348  ·  view source on GitHub ↗

Return a new array 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 result.

(a, dtype=None, order="C", chunks=None, name=None, shape=None)

Source from the content-addressed store, hash-verified

287
288
289def empty_like(a, dtype=None, order="C", chunks=None, name=None, shape=None):
290 """
291 Return a new array with the same shape and type as a given array.
292
293 Parameters
294 ----------
295 a : array_like
296 The shape and data-type of `a` define these same attributes of the
297 returned array.
298 dtype : data-type, optional
299 Overrides the data type of the result.
300 order : {'C', 'F'}, optional
301 Whether to store multidimensional data in C- or Fortran-contiguous
302 (row- or column-wise) order in memory.
303 chunks : sequence of ints
304 The number of samples on each block. Note that the last block will have
305 fewer samples if ``len(array) % chunks != 0``.
306 name : str, optional
307 An optional keyname for the array. Defaults to hashing the input
308 keyword arguments.
309 shape : int or sequence of ints, optional.
310 Overrides the shape of the result.
311
312 Returns
313 -------
314 out : ndarray
315 Array of uninitialized (arbitrary) data with the same
316 shape and type as `a`.
317
318 See Also
319 --------
320 ones_like : Return an array of ones with shape and type of input.
321 zeros_like : Return an array of zeros with shape and type of input.
322 empty : Return a new uninitialized array.
323 ones : Return a new array setting values to one.
324 zeros : Return a new array setting values to zero.
325
326 Notes
327 -----
328 This function does *not* initialize the returned array; to do that use
329 `zeros_like` or `ones_like` instead. It may be marginally faster than
330 the functions that do set the array values.
331 """
332
333 a = asarray(a, name=False)
334 shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape)
335
336 # if shape is nan we cannot rely on regular empty function, we use
337 # generic map_blocks.
338 if np.isnan(shape).any():
339 return a.map_blocks(partial(np.empty_like, dtype=(dtype or a.dtype)))
340
341 return empty(
342 shape,
343 dtype=(dtype or a.dtype),
344 order=order,
345 chunks=chunks,
346 name=name,

Callers 1

add_dummy_paddingFunction · 0.90

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…