MCPcopy Create free account
hub / github.com/numpy/numpy / full_like

Function full_like

numpy/core/numeric.py:342–408  ·  view source on GitHub ↗

Return a full 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. fill_value : array_like Fill value. dtype : data-type, optional

(a, fill_value, dtype=None, order='K', subok=True, shape=None)

Source from the content-addressed store, hash-verified

340
341@array_function_dispatch(_full_like_dispatcher)
342def full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None):
343 """
344 Return a full array with the same shape and type as a given array.
345
346 Parameters
347 ----------
348 a : array_like
349 The shape and data-type of `a` define these same attributes of
350 the returned array.
351 fill_value : array_like
352 Fill value.
353 dtype : data-type, optional
354 Overrides the data type of the result.
355 order : {'C', 'F', 'A', or 'K'}, optional
356 Overrides the memory layout of the result. 'C' means C-order,
357 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
358 'C' otherwise. 'K' means match the layout of `a` as closely
359 as possible.
360 subok : bool, optional.
361 If True, then the newly created array will use the sub-class
362 type of `a`, otherwise it will be a base-class array. Defaults
363 to True.
364 shape : int or sequence of ints, optional.
365 Overrides the shape of the result. If order='K' and the number of
366 dimensions is unchanged, will try to keep order, otherwise,
367 order='C' is implied.
368
369 .. versionadded:: 1.17.0
370
371 Returns
372 -------
373 out : ndarray
374 Array of `fill_value` with the same shape and type as `a`.
375
376 See Also
377 --------
378 empty_like : Return an empty array with shape and type of input.
379 ones_like : Return an array of ones with shape and type of input.
380 zeros_like : Return an array of zeros with shape and type of input.
381 full : Return a new array of given shape filled with value.
382
383 Examples
384 --------
385 >>> x = np.arange(6, dtype=int)
386 >>> np.full_like(x, 1)
387 array([1, 1, 1, 1, 1, 1])
388 >>> np.full_like(x, 0.1)
389 array([0, 0, 0, 0, 0, 0])
390 >>> np.full_like(x, 0.1, dtype=np.double)
391 array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
392 >>> np.full_like(x, np.nan, dtype=np.double)
393 array([nan, nan, nan, nan, nan, nan])
394
395 >>> y = np.arange(6, dtype=np.double)
396 >>> np.full_like(y, 0.1)
397 array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
398
399 >>> y = np.zeros([2, 2, 3], dtype=int)

Callers

nothing calls this directly

Calls 1

empty_likeFunction · 0.70

Tested by

no test coverage detected