【发布时间】:2020-10-22 23:21:42
【问题描述】:
我有以下代码:
for (old_point, new_point) in zip(masked_indices, masked_new_indices):
row, col = old_point
new_row, new_col = new_point
new_img[row, col] = img[new_row, new_col]
new_img 和 img 都是 1024x1024x3 ndarray,masked_indices 和 masked_new_indices 都是 80000x2 ndarray。
为什么这个语句的行为不同?
new_img[masked_indices] = img[masked_new_indices]
有没有办法将这个 for 循环优化成更接近 NumPy 的风格?
【问题讨论】: