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 toTrue
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
References
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.]])