2
저는 python과 numpy를 사용하여 특징 수 행렬의 summed area table을 계산하려고합니다. 현재 I는 다음과 같은 코드가 사용하고Numpy로 효율적인 합계 면적 계산
가def summed_area_table(img):
table = np.zeros_like(img).astype(int)
for row in range(img.shape[0]):
for col in range(img.shape[1]):
if (row > 0) and (col > 0):
table[row, col] = (img[row, col] +
table[row, col - 1] +
table[row - 1, col] -
table[row - 1, col - 1])
elif row > 0:
table[row, col] = img[row, col] + table[row - 1, col]
elif col > 0:
table[row, col] = img[row, col] + table[row, col - 1]
else:
table[row, col] = img[row, col]
return table
상기 코드는 3200 X 1400 어레이의 계산을 수행하는 약 35 초가 걸린다. Numpy 트릭을 사용하여 계산 속도를 높이는 방법이 있습니까? 근본적인 속도 문제가 중첩 된 파이썬 루프에 있다는 것을 알았지 만이를 피하는 방법을 모른다.