求助!一个1000*1024的二维矩阵,想每隔100列中随机抽取50列出来
求助!最近在学机器学习,现在一共有1000张图片,每一百张代表一个数字,想从中随机抽取50个用作KNN算法
一个1000*1024的二维矩阵,想每隔100行中随机抽取50行出来
def handwritingClassTest():
hwLabels = []
trainingFileList = listdir('trainingDigits')
m = len(trainingFileList)
trainingMat = np.zeros((m, 1024))
for i in range(m):
fileNameStr = trainingFileList
classNumber = int(fileNameStr.split('_'))
hwLabels.append(classNumber)
trainingMat = img2vector('trainingDigits/%s' % (fileNameStr))
试试 sample 函数,随机抽取不重复
import random
for i in range(m):
if not (i % 100):
result = random.sample(trainingFileList, 50)
print(result)
主贴没有表达清楚,0到100抽50,100到200抽50.。。。。。。。。以此类推,最后自己解决方案如下
trainingSet=[]
for j in range(10):
a=random.sample(range(0,100),50)
for k in a:
trainingSet.append(k+100*j)
页:
[1]