mygrad.full_like#

mygrad.full_like(other: ArrayLike, fill_value: int | float, dtype: DTypeLikeReals | None = None, shape: int | Sequence[int] | None = None, constant: bool | None = None) Tensor[source]#

Return a Tensor of the same shape and type as the given, filled with fill_value.

This docstring was adapted from numpy.full_like [1]

Parameters:
otherArrayLike

The tensor or array whose shape and datatype should be mirrored.

fill_valueReal

The value with which to fill the output Tensor.

dtypeOptional[DTypeLikeReals]

Override the data type of the returned Tensor with this value, or None to not override.

shapeOptional[int, Sequence[int]]

If specified, overrides the shape of the result

constantOptional[bool]

If True, this tensor is a constant, and thus does not facilitate back propagation. If None then:

Inferred from other, if other is a tensor Defaults to False for float-type data. Defaults to True for integer-type data.

Returns:
Tensor

A Tensor of fill_value whose shape and data type match other.

References

Examples

>>> import mygrad as mg
>>> x = mg.arange(6, dtype=int)
>>> mg.full_like(x, 1)
Tensor([1, 1, 1, 1, 1, 1])
>>> mg.full_like(x, 0.1)
Tensor([0, 0, 0, 0, 0, 0])
>>> mg.full_like(x, 0.1, dtype=np.double)
Tensor([ 0.1,  0.1,  0.1,  0.1,  0.1,  0.1])
>>> mg.full_like(x, np.nan, dtype=np.double)
Tensor([ nan,  nan,  nan,  nan,  nan,  nan])
>>> y = mg.arange(6, dtype=np.double)
>>> mg.full_like(y, 0.1)
Tensor([ 0.1,  0.1,  0.1,  0.1,  0.1,  0.1])