I am looking to vectorize a nested loop that will work in a list of 300,000 lists, with each of these lists containing 3 values. The nested loop compares the values โโof each of the lists with the corresponding values โโin other lists and adds only the list indices for which the corresponding values โโhave a maximum difference of 0.1 between them. Thus, a list containing [0.234, 0.456, 0.567] and a list containing [0.246, 0.479, 0.580] falls into this category because their respective values โโ(ie 0.234 and 0.246, 0.456 and 0.479, 0.567 and 0.580 ) have a difference of less than 0.1 between them.
I currently use the following nested loop for this, but it currently takes about 58 hours (a total of 90 trillion iterations);
import numpy as np variable = np.random.random((300000,3)).tolist() out1=list() out2=list() for i in range(0:300000): for j in range(0:300000): if ((i<j) and ((abs(variable[i][0]-variable[j][0]))<0.1) and ((abs(variable[i][1]-variable[j] [1]))<0.1) and ((abs(variable[i][2]-variable[j][2]))<0.1)): out1.append(i) out2.append(j)
source share