标签:import dom random 组元 shuff int 输出 range print
for in 循环所实现的是按照序号顺序读取,而不是按照数组元素。
import numpy as np
index = np.arange(20)
print(index)
for i in index:
print(i)
np.random.shuffle(index)
print(index)
输出
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]
0
[15 12 19 11 6 2 16 5 1 17 7 18 8 4 13 9 0 14 3 10]
12
[14 3 11 1 0 18 10 8 12 2 19 15 6 5 9 16 7 13 17 4]
11
[12 6 2 19 13 1 11 17 14 3 18 5 8 9 16 15 10 7 0 4]
19
[ 6 7 2 5 18 14 8 19 13 4 16 3 15 17 0 12 11 1 9 10]
18
[14 18 7 8 15 12 6 3 5 17 13 16 11 9 4 19 2 0 10 1]
12
[14 5 8 3 18 0 13 15 9 1 7 10 12 2 4 19 6 16 17 11]
13
[ 1 0 16 11 14 8 5 15 18 19 3 7 13 9 17 4 6 2 10 12]
15
[ 3 14 11 8 12 1 0 16 19 6 4 17 7 5 10 15 2 18 9 13]
19
[ 4 17 9 18 19 8 7 10 16 14 5 0 12 13 3 2 11 6 1 15]
14
[ 8 14 2 19 16 5 7 13 17 6 1 15 10 11 9 4 0 18 3 12]
1
[ 9 1 7 6 2 0 16 15 10 11 14 12 19 18 17 5 8 3 4 13]
12
[ 3 9 19 18 16 17 1 6 12 0 5 13 10 15 2 4 7 8 11 14]
10
[10 12 11 16 1 4 5 14 9 13 19 3 18 2 6 17 15 0 7 8]
2
[10 3 12 5 6 17 0 8 14 11 7 2 4 16 9 18 1 13 19 15]
9
[ 4 2 9 15 19 7 11 3 5 12 18 8 16 10 14 0 6 13 1 17]
0
[ 0 17 2 5 9 18 13 4 10 15 3 7 19 12 6 16 11 14 8 1]
11
[ 3 17 1 7 16 8 18 12 0 10 5 15 14 19 4 9 13 2 6 11]
2
[ 7 2 9 5 12 16 6 11 8 19 13 18 10 14 1 17 15 4 3 0]
3
[11 0 6 5 14 15 10 19 2 12 1 13 18 4 9 16 3 7 17 8]
8
[11 0 9 12 1 2 5 16 8 7 17 4 19 6 13 10 14 15 18 3]
标签:import dom random 组元 shuff int 输出 range print
原文地址:https://www.cnblogs.com/venusian/p/12517357.html