###随机函数的使用,且不重复的使用旧数据的技巧
from numpy import *
dataIndex = range(20)
for i in range(20):
print '================='
print dataIndex
randIndex = int(random.uniform(0,len(dataIndex)))
print randIndex
del(dataIndex[randIndex])
print dataIndex
i += 1
if i >= 3:
break
结果:
=================
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
5
[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
=================
[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
7
[0, 1, 2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
=================
[0, 1, 2, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
2
[0, 1, 3, 4, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]