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

Function ones_like

dask/array/creation.py:122–174  ·  view source on GitHub ↗

Return an array of ones 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 resu

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

Source from the content-addressed store, hash-verified

120
121
122def ones_like(a, dtype=None, order="C", chunks=None, name=None, shape=None):
123 """
124 Return an array of ones with the same shape and type as a given array.
125
126 Parameters
127 ----------
128 a : array_like
129 The shape and data-type of `a` define these same attributes of
130 the returned array.
131 dtype : data-type, optional
132 Overrides the data type of the result.
133 order : {'C', 'F'}, optional
134 Whether to store multidimensional data in C- or Fortran-contiguous
135 (row- or column-wise) order in memory.
136 chunks : sequence of ints
137 The number of samples on each block. Note that the last block will have
138 fewer samples if ``len(array) % chunks != 0``.
139 name : str, optional
140 An optional keyname for the array. Defaults to hashing the input
141 keyword arguments.
142 shape : int or sequence of ints, optional.
143 Overrides the shape of the result.
144
145 Returns
146 -------
147 out : ndarray
148 Array of ones with the same shape and type as `a`.
149
150 See Also
151 --------
152 zeros_like : Return an array of zeros with shape and type of input.
153 empty_like : Return an empty array with shape and type of input.
154 zeros : Return a new array setting values to zero.
155 ones : Return a new array setting values to one.
156 empty : Return a new uninitialized array.
157 """
158
159 a = asarray(a, name=False)
160 shape, chunks = _get_like_function_shapes_chunks(a, chunks, shape)
161
162 # if shape is nan we cannot rely on regular ones function, we use
163 # generic map_blocks.
164 if np.isnan(shape).any():
165 return a.map_blocks(partial(np.ones_like, dtype=(dtype or a.dtype)))
166
167 return ones(
168 shape,
169 dtype=(dtype or a.dtype),
170 order=order,
171 chunks=chunks,
172 name=name,
173 meta=a._meta,
174 )
175
176
177def zeros_like(a, dtype=None, order="C", 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…