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. IfNone
then:Inferred from
other
, if other is a tensor Defaults toFalse
for float-type data. Defaults toTrue
for integer-type data.
- Returns:
- Tensor
A tensor of uninitialized data whose shape and type match other.
See also
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.empty_like.html
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