mindspore.Tensor.random_
- Tensor.random_(from_=0, to=None, *, generator=None)[source]
Fill the tensor with numbers sampled from a discrete uniform distribution over an interval \([from\_, to-1]\).
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
from_ (Union[number.Number, Tensor], optional) – the lower bound of the generated random number. It can be a scalar value or a tensor of any dimension with only a single element. Default: 0.
to (Union[number.Number, Tensor], optional) – the upper bound of the generated random number. By default it's the upper limit of the input data type. It can be a scalar value or a tensor of any dimension with only a single element. Default:
None
.
- Keyword Arguments
generator (
mindspore.Generator
, optional) – a pseudorandom number generator. Default:None
, uses the default pseudorandom number generator.- Returns
The input tensor.
- Raises
TypeError – If from_ or to is not integer.
RuntimeError – If from_ >= to.
- Supported Platforms:
Ascend
Examples
>>> from mindspore import Tensor >>> a = Tensor([[2, 3, 4], [1, 2, 3]]) >>> from_ = 0 >>> to = 5 >>> print(a.random_(low, high).shape) (2, 3)