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

Function empty_like

dask/array/creation.py:60–119  ·  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

58
59
60def empty_like(a, dtype=None, order="C", chunks=None, name=None, shape=None):
61 """
62 Return a new array with the same shape and type as a given array.
63
64 Parameters
65 ----------
66 a : array_like
67 The shape and data-type of `a` define these same attributes of the
68 returned array.
69 dtype : data-type, optional
70 Overrides the data type of the result.
71 order : {'C', 'F'}, optional
72 Whether to store multidimensional data in C- or Fortran-contiguous
73 (row- or column-wise) order in memory.
74 chunks : sequence of ints
75 The number of samples on each block. Note that the last block will have
76 fewer samples if ``len(array) % chunks != 0``.
77 name : str, optional
78 An optional keyname for the array. Defaults to hashing the input
79 keyword arguments.
80 shape : int or sequence of ints, optional.
81 Overrides the shape of the result.
82
83 Returns
84 -------
85 out : ndarray
86 Array of uninitialized (arbitrary) data with the same
87 shape and type as `a`.
88
89 See Also
90 --------
91 ones_like : Return an array of ones with shape and type of input.
92 zeros_like : Return an array of zeros with shape and type of input.
93 empty : Return a new uninitialized array.
94 ones : Return a new array setting values to one.
95 zeros : Return a new array setting values to zero.
96
97 Notes
98 -----
99 This function does *not* initialize the returned array; to do that use
100 `zeros_like` or `ones_like` instead. It may be marginally faster than
101 the functions that do set the array values.
102 """
103
104 a = asarray(a, name=False)
105 shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape)
106
107 # if shape is nan we cannot rely on regular empty function, we use
108 # generic map_blocks.
109 if np.isnan(shape).any():
110 return a.map_blocks(partial(np.empty_like, dtype=(dtype or a.dtype)))
111
112 return empty(
113 shape,
114 dtype=(dtype or a.dtype),
115 order=order,
116 chunks=chunks,
117 name=name,

Callers 2

add_dummy_paddingFunction · 0.90
pad_edgeFunction · 0.70

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…