I have a nested for loop:
import numpy as np
ccounter = np.zeros(shape=(120, 200))
lat_idx = np.random.randint(120, size=4800)
lon_idx = np.random.randint(200, size=(4800, 4800))
for j in range(4800):
for i in range(4800):
ccounter[lat_idx[i], lon_idx[i, j]] +=1
This is obviously very slow. Is it possible to avoid the for loops and implement it as e.g. matrix operation?
lat_idxandlon_idx(the order is important) occur. In the example above I used randoms for simplicity. There is probably a more elegant solution.