What's the most efficient way to increment an array by a reference while broadcasting row to column in NumPy Python? Can it be vectorized?
问题 I have this piece of code in Python for i in range(len(ax)): for j in range(len(rx)): x = ax[i] + rx[j] y = ay[i] + ry[j] A[x,y] = A[x,y] + 1 where A.shape = (N,M) ax.shape = ay.shape = (L) rx.shape = ry.shape = (K) I wanted to vectorize or otherwise make it more efficient, i.e. faster, and if possible more economical in memory consumption. Here, my ax and ay refer to the absolute elements of an array A, while rx and ay are relative coordinates. So, I'm updating the counter array A. My table