maxframe.tensor.random.permutation#

maxframe.tensor.random.permutation(x, axis=0, chunk_size=None)[源代码]#

随机排列一个序列,或返回一个排列后的范围。

参数:
  • x (int or array_like) -- 如果 x 是一个整数,则随机排列 mt.arange(x)。如果 x 是一个数组,则复制并随机打乱元素。

  • axis (int, optional) -- x 被打乱的轴。默认是 0。

  • chunk_size (: int or tuple of int or tuple of ints, optional) -- 每个维度上期望的块大小

返回:

out -- 排列后的序列或张量范围。

返回类型:

Tensor

示例

>>> import maxframe.tensor as mt
>>> rng = mt.random.RandomState()
>>> rng.permutation(10).execute()
array([1, 2, 3, 7, 9, 8, 0, 6, 4, 5]) # random
>>> rng.permutation([1, 4, 9, 12, 15]).execute()
array([ 9,  4, 12,  1, 15]) # random
>>> arr = mt.arange(9).reshape((3, 3))
>>> rng.permutation(arr).execute()
array([[3, 4, 5], # random
       [6, 7, 8],
       [0, 1, 2]])
>>> rng.permutation("abc")
Traceback (most recent call last):
    ...
numpy.AxisError: x must be an integer or at least 1-dimensional