다음 for 루프를 numpy로 밀어 넣으면 더 빠르게 처리 할 수 있습니까? 로for 루프를 numpy로 푸시
bestepsilons = numpy.zeros((R.shape[0]))
for i in range(R.shape[0]):
bestindex = numpy.nanargmin(R[i,:])
if(numpy.isnan(bestindex)):
bestepsilons[i]=numpy.nan
else:
bestepsilons[i]=epsilon[bestindex]
과 (혼자) 해결되었다 : 지금
bestepsilons1 = numpy.zeros(R.shape[0])+numpy.nan
d0 = numpy.nanmin(R, axis=1) # places where the best index is not a nan
bestepsilons1[~numpy.isnan(d0)] = epsilon[numpy.nanargmin(R[~numpy.isnan(d0),:], axis=1)]
그러나 더
ri = numpy.zeros((R.shape[0],R.shape[2]))
for i in range(R.shape[0]):
ri[i, :] = R[i, indices[i], :]
이이 비트 속도를했다 내 이전 질문 making numpy.nanargmin return nan if column is all nan에 관한 복잡한 경우 :
bestepsilons = numpy.zeros((R.shape[0]))
for i in range(R.shape[0]):
bestindex = numpy.nanargmin(R[i,indices[i],:])
if(numpy.isnan(bestindex)):
bestepsilons[i]=numpy.nan
else:
bestepsilons[i]=epsilon[bestindex]
그리고 지금이 트릭은 그 인덱스가 더 이상 작동하지 않는 최고의 인덱스가 아닌 장소를 보여줍니다.