mygrad.empty#

mygrad.empty(shape: ~typing.Union[~typing.Sequence[int], int], dtype: ~mygrad.typing._dtype_like.DTypeLikeReals = <class 'numpy.float32'>, *, constant: ~typing.Optional[bool] = None) Tensor[source]#

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

This docstring was adapted from numpy.empty [1]

Parameters
shapeUnion[int, Tuple[int]]

The shape of the empty array.

dtypedata-type, optional (default=numpy.float32)

The data type of the output Tensor.

constantOptional[bool]

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

Defaults to False for float-type data. Defaults to True for integer-type data.

Integer-type tensors must be constant.

Returns
Tensor

A tensor of uninitialized data of the given shape and dtype.

See also

empty_like

Return an empty tensor with shape and type of input.

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.

Notes

empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution.

References

1

Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.empty.html

Examples

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