mindspore.ops.randint_like

View Source On Gitee
mindspore.ops.randint_like(input, low, high, seed=None, *, dtype=None)[source]

Returns a tensor with the same shape as Tensor input whose elements are random integers in the range of [ low , high ) .

Parameters
  • input (Tensor) – Input Tensor to specify the output shape and its default dtype.

  • low (int) – Start value of interval.

  • high (int) – End value of interval.

  • seed (int, optional) – Random seed, must be greater or equal to 0. Default: None , and 0 will be used.

Keyword Arguments

dtype (mindspore.dtype, optional) – Designated tensor dtype, it must be int type. If None , the same dtype of input will be applied. Default: None .

Returns

Tensor, with the designated shape and dtype, filled with random integers from low (inclusive) to high (exclusive).

Raises
  • TypeErrorseed is not a non-negative integer.

  • TypeErrorlow or high is not an integer.

  • ValueError – If dtype is not a mstype.int_type.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import Tensor, ops
>>> a = Tensor([[1, 2, 3], [3, 2, 1]])
>>> print(ops.randint_like(a, 1, 10))
[[4 9 7]
 [9 1 2]]