方法
random.Generator.
permuted
随机排列 x 沿轴线 axis .
不像 shuffle ,沿给定轴的每个片独立于其他片进行洗牌。
shuffle
要洗牌的数组。
切片 x 在这个轴上,所有的人都被洗牌了。每个片段都独立于其他片段进行洗牌。如果 axis 如果为“无”,则展开的数组将被洗牌。
如果给定,这就是洗牌数组的目的地。如果 out 如果为“无”,则返回数组的无序副本。
如果 out 是无,是 x 已返回。否则,洗牌数组将存储在 out 和 out 返回
参见
permutation
实例
创建一个 numpy.random.Generator 实例:
numpy.random.Generator
>>> rng = np.random.default_rng()
创建测试数组:
>>> x = np.arange(24).reshape(3, 8) >>> x array([[ 0, 1, 2, 3, 4, 5, 6, 7], [ 8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23]])
洗牌 x :
>>> y = rng.permuted(x, axis=1) >>> y array([[ 4, 3, 6, 7, 1, 2, 5, 0], # random [15, 10, 14, 9, 12, 11, 8, 13], [17, 16, 20, 21, 18, 22, 23, 19]])
x 尚未修改:
>>> x array([[ 0, 1, 2, 3, 4, 5, 6, 7], [ 8, 9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23]])
洗牌 x 到位,通过 x 作为 out 参数:
>>> y = rng.permuted(x, axis=1, out=x) >>> x array([[ 3, 0, 4, 7, 1, 6, 2, 5], # random [ 8, 14, 13, 9, 12, 11, 15, 10], [17, 18, 16, 22, 19, 23, 20, 21]])
注意,当 out 参数,返回值为 out :
out
>>> y is x True