MCPcopy Index your code
hub / github.com/numpy/numpy / full_like

Function full_like

numpy/_core/numeric.py:401–476  ·  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,
    *, device=None
)

Source from the content-addressed store, hash-verified

399
400@array_function_dispatch(_full_like_dispatcher)
401def full_like(
402 a, fill_value, dtype=None, order='K', subok=True, shape=None,
403 *, device=None
404):
405 """
406 Return a full array with the same shape and type as a given array.
407
408 Parameters
409 ----------
410 a : array_like
411 The shape and data-type of `a` define these same attributes of
412 the returned array.
413 fill_value : array_like
414 Fill value.
415 dtype : data-type, optional
416 Overrides the data type of the result.
417 order : {'C', 'F', 'A', or 'K'}, optional
418 Overrides the memory layout of the result. 'C' means C-order,
419 'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
420 'C' otherwise. 'K' means match the layout of `a` as closely
421 as possible.
422 subok : bool, optional.
423 If True, then the newly created array will use the sub-class
424 type of `a`, otherwise it will be a base-class array. Defaults
425 to True.
426 shape : int or sequence of ints, optional.
427 Overrides the shape of the result. If order='K' and the number of
428 dimensions is unchanged, will try to keep order, otherwise,
429 order='C' is implied.
430 device : str, optional
431 The device on which to place the created array. Default: None.
432 For Array-API interoperability only, so must be ``"cpu"`` if passed.
433
434 .. versionadded:: 2.0.0
435
436 Returns
437 -------
438 out : ndarray
439 Array of `fill_value` with the same shape and type as `a`.
440
441 See Also
442 --------
443 empty_like : Return an empty array with shape and type of input.
444 ones_like : Return an array of ones with shape and type of input.
445 zeros_like : Return an array of zeros with shape and type of input.
446 full : Return a new array of given shape filled with value.
447
448 Examples
449 --------
450 >>> import numpy as np
451 >>> x = np.arange(6, dtype=np.int_)
452 >>> np.full_like(x, 1)
453 array([1, 1, 1, 1, 1, 1])
454 >>> np.full_like(x, 0.1)
455 array([0, 0, 0, 0, 0, 0])
456 >>> np.full_like(x, 0.1, dtype=np.float64)
457 array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
458 >>> np.full_like(x, np.nan, dtype=np.float64)

Callers

nothing calls this directly

Calls 1

empty_likeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…