mygrad.empty_like#
- mygrad.empty_like(other: ArrayLike, dtype: Optional[DTypeLikeReals] = None, shape: Optional[Union[int, Sequence[int]]] = None, *, constant: Optional[bool] = 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
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