MCPcopy
hub / github.com/dask/dask / zeros_like

Function zeros_like

dask/array/_array_expr/_creation.py:406–458  ·  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

404
405
406def zeros_like(a, dtype=None, order="C", chunks=None, name=None, shape=None):
407 """
408 Return an array of zeros with the same shape and type as a given array.
409
410 Parameters
411 ----------
412 a : array_like
413 The shape and data-type of `a` define these same attributes of
414 the returned array.
415 dtype : data-type, optional
416 Overrides the data type of the result.
417 order : {'C', 'F'}, optional
418 Whether to store multidimensional data in C- or Fortran-contiguous
419 (row- or column-wise) order in memory.
420 chunks : sequence of ints
421 The number of samples on each block. Note that the last block will have
422 fewer samples if ``len(array) % chunks != 0``.
423 name : str, optional
424 An optional keyname for the array. Defaults to hashing the input
425 keyword arguments.
426 shape : int or sequence of ints, optional.
427 Overrides the shape of the result.
428
429 Returns
430 -------
431 out : ndarray
432 Array of zeros with the same shape and type as `a`.
433
434 See Also
435 --------
436 ones_like : Return an array of ones with shape and type of input.
437 empty_like : Return an empty array with shape and type of input.
438 zeros : Return a new array setting values to zero.
439 ones : Return a new array setting values to one.
440 empty : Return a new uninitialized array.
441 """
442
443 a = asarray(a, name=False)
444 shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape)
445
446 # if shape is nan we cannot rely on regular zeros function, we use
447 # generic map_blocks.
448 if np.isnan(shape).any():
449 return a.map_blocks(partial(np.zeros_like, dtype=(dtype or a.dtype)))
450
451 return zeros(
452 shape,
453 dtype=(dtype or a.dtype),
454 order=order,
455 chunks=chunks,
456 name=name,
457 meta=a._meta,
458 )
459
460
461def full(shape, fill_value, *args, **kwargs):

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…