我有一个图像,我的子样本
Count=0
classim = np.zeros([temp1.shape[0],temp1.shape[1]])
for rows in range(int(np.floor(temp1.shape[0]/SAMPLE_SIZE))):
for cols in range(int(np.floor(temp1.shape[1]/SAMPLE_SIZE))):
classim[np.multiply(rows,SAMPLE_SIZE):np.multiply(rows+1,SAMPLE_SIZE),
np.multiply(cols,SAMPLE_SIZE):np.multiply(cols+1,SAMPLE_SIZE)] = predict.argmax(axis=-1)[Count]
Count = np.add(Count,1)
这太慢了。我的标签来自“预测.argmax(axis=-1)[Count]“,当然可以是向量形式。 换言之,如何对上述循环进行矢量化?
将行计算放在内部循环之外会有一点帮助。因此,每行只进行一次计算。你知道吗
其他一些整理可以:
在我做更多之前,你需要告诉我们更多关于预测对象的信息。但这些改变会有一点帮助。你知道吗
编辑
你可以利用numpy.重复功能。那么就不需要遍历整个classim:
相关问题 更多 >
编程相关推荐