=================================版权声明=================================
版权声明:原创文章 谢绝转载
请通过右侧公告中的“联系邮箱(wlsandwho@)”联系我
勿用于学术性引用。
勿用于商业出版、商业印刷、商业引用以及其他商业用途。
本文不定期修正完善。
=======================================================================
从集合中随机抽取元素(不放回)
1 importmath2 from numpy import *
3
4
5 dataIndex=list(range(20))6 print(dataIndex)7 print('----------')8 for i in range(20):9 randIndex =random.choice(dataIndex) #go to 0 because of the constant
10 print(randIndex)11 del(dataIndex[dataIndex.index(randIndex)])12 print(dataIndex)13 print('----------')14 print('\n')
运行结果
"C:\Program Files\Python36-32\python.exe" C:/PythonResearch/LogisticRegression/Test_logRegres.py
[0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]----------
15[0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19]----------
8[0,1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19]----------
14[0,1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 16, 17, 18, 19]----------
4[0,1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 13, 16, 17, 18, 19]----------
3[0,1, 2, 5, 6, 7, 9, 10, 11, 12, 13, 16, 17, 18, 19]----------
10[0,1, 2, 5, 6, 7, 9, 11, 12, 13, 16, 17, 18, 19]----------
6[0,1, 2, 5, 7, 9, 11, 12, 13, 16, 17, 18, 19]----------
9[0,1, 2, 5, 7, 11, 12, 13, 16, 17, 18, 19]----------
16[0,1, 2, 5, 7, 11, 12, 13, 17, 18, 19]----------
19[0,1, 2, 5, 7, 11, 12, 13, 17, 18]----------
7[0,1, 2, 5, 11, 12, 13, 17, 18]----------0
[1, 2, 5, 11, 12, 13, 17, 18]----------
13[1, 2, 5, 11, 12, 17, 18]----------
2[1, 5, 11, 12, 17, 18]----------
1[5, 11, 12, 17, 18]----------
12[5, 11, 17, 18]----------
18[5, 11, 17]----------
5[11, 17]----------
17[11]----------
11[]----------Process finished with exit code 0