If I have two numpy arrays of values; how can I quickly make a third array that gives me the number of times I have the same two values in the first two arrays?
For example:
x = np.round(np.random.random(2500),2)
xIndex = np.linspace(0, 1, 100)
y = np.round(np.random.random(2500)*10,2)
yIndex = np.linspace(0, 10, 1000)
z = np.zeros((100,1000))
Right now, I'm doing the following loop (which is prohibitively slow):
for m in x:
for n in y:
q = np.where(xIndex == m)[0][0]
l = np.where(yIndex == n)[0][0]
z[q][l] += 1
Then I can do a contour plot (or heat map, or whatever) of xIndex, yIndex, and z. But I know I'm not doing a "Pythonic" way of solving this, and there's just no way for me to run over the hundreds of millions of data points I have for this in anything approaching a reasonable timeframe.
How do I do this the right way? Thanks for reading!