mygrad.empty_like#

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

Return a new Tensor of the same shape and type as the given array.

This docstring was adapted from numpy.empty_like [1]

Parameters:
otherArrayLike

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

dtypeOptional[DTypeLikeReals]

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

shapeOptional[Union[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 uninitialized data whose shape and type match other.

See also

empty

Return a new Tensor of the given shape and type, without initializing entries.

ones

Return a new tensor setting values to one.

zeros

Return a new tensor setting values to zero.

full

Return a new tensor of given shape filled with value.

References

Examples

>>> import mygrad as mg
>>> x = mg.arange(4).reshape(2, 2)
>>> mg.empty_like(x, constant=True)
Tensor([[ -9.74499359e+001,   6.69583040e-309],
        [  2.13182611e-314,   3.06959433e-309]])         #random
>>> mg.empty_like(x, dtype=int)
Tensor([[-1073741821, -1067949133],
        [  496041986,    19249760]])                     #random