mygrad.zeros#

mygrad.zeros(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 Tensor of the given shape and type, filled with zeros.

This docstring was adapted from numpy.zeros [1]

Parameters
shapeUnion[int, Tuple[int]]

The shape of the output Tensor.

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 zeros with the given shape and data type.

See also

ones_like

Return an tensor of ones with shape and type of input.

empty

Return a new uninitialized tensor.

ones

Return a new tensor setting values to one.

full

Return a new tensor of given shape filled with value.

References

1

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

Examples

>>> import mygrad as mg
>>> mg.zeros(5)
Tensor([ 0.,  0.,  0.,  0.,  0.])
>>> mg.zeros((5,), dtype=int, constant=True) # tensor will not back-propagate a gradient
Tensor([0, 0, 0, 0, 0])
>>> mg.zeros((2, 1))
Tensor([[ 0.],
        [ 0.]])
>>> mg.zeros((2, 2))
Tensor([[ 0.,  0.],
        [ 0.,  0.]])