flopscope.numpy.full_like
fnp.full_like(a, fill_value, dtype=None, order='K', subok=True, shape=None, *, device=None)[flopscope source][numpy source]
Return a full array with the same shape and type as a given array.
Adapted from NumPy docs np.full_like
Array filled with scalar, same shape/type as input. Cost: numel(output).
Parameters
- a:array_like
The shape and data-type of
adefine these same attributes of the returned array.- fill_value:array_like
Fill value.
- dtype:data-type, optional
Overrides the data type of the result.
- order:{'C', 'F', 'A', or 'K'}, optional
Overrides the memory layout of the result. 'C' means C-order, 'F' means F-order, 'A' means 'F' if
ais Fortran contiguous, 'C' otherwise. 'K' means match the layout ofaas closely as possible.- subok:bool, optional.
If True, then the newly created array will use the sub-class type of
a, otherwise it will be a base-class array. Defaults to True.- shape:int or sequence of ints, optional.
Overrides the shape of the result. If order='K' and the number of dimensions is unchanged, will try to keep order, otherwise, order='C' is implied.
- device:str, optional
The device on which to place the created array. Default: None. For Array-API interoperability only, so must be
"cpu"if passed.Added in version 2.0.0.
Returns
- out:ndarray
Array of
fill_valuewith the same shape and type asa.
See also
- we.flops.empty_like Return an empty array with shape and type of input.
- we.flops.ones_like Return an array of ones with shape and type of input.
- we.flops.zeros_like Return an array of zeros with shape and type of input.
- we.flops.full Return a new array of given shape filled with value.
Examples
>>> import flopscope.numpy as fnp
>>> x = flops.arange(6, dtype=int)
>>> flops.full_like(x, 1)
array([1, 1, 1, 1, 1, 1])
>>> flops.full_like(x, 0.1)
array([0, 0, 0, 0, 0, 0])
>>> flops.full_like(x, 0.1, dtype=flops.double)
array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])
>>> flops.full_like(x, flops.nan, dtype=flops.double)
array([nan, nan, nan, nan, nan, nan])>>> y = flops.arange(6, dtype=flops.double)
>>> flops.full_like(y, 0.1)
array([0.1, 0.1, 0.1, 0.1, 0.1, 0.1])>>> y = flops.zeros([2, 2, 3], dtype=int)
>>> flops.full_like(y, [0, 0, 255])
array([[[ 0, 0, 255],
[ 0, 0, 255]],
[[ 0, 0, 255],
[ 0, 0, 255]]])