mygrad.ones#
- mygrad.ones(shape: ~typing.Sequence[int] | int, dtype: ~mygrad.typing._dtype_like.DTypeLikeReals = <class 'numpy.float32'>, *, constant: bool | None = None) Tensor [source]#
Return a Tensor of the given shape and type, filled with ones.
This docstring was adapted from
numpy.ones
[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 ones with the given shape and data type.
See also
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.ones.html
Examples
>>> import mygrad as mg >>> mg.ones(5) Tensor([ 1., 1., 1., 1., 1.])
>>> mg.ones((5,), dtype=int) Tensor([1, 1, 1, 1, 1])
>>> mg.ones((2, 1)) Tensor([[ 1.], [ 1.]])
>>> mg.ones((2, 2)) Tensor([[ 1., 1.], [ 1., 1.]])