I just started to learn a little numpy because of High - performance least squares calculation is different from all possible combinations (n lists) :
I started calculations right now and could use some help.
I have a numpy array object that looks like this:
>>> items array([[ 246, 1143, 1491, ..., 1167, 325, 1158], [ 246, 1143, 1491, ..., 1167, 519, 1158], [ 246, 1143, 1491, ..., 1167, 507, 1158], ..., [1491, 1143, 246, ..., 1167, 325, 1158], [1491, 1143, 246, ..., 1167, 519, 1158], [1491, 1143, 246, ..., 1167, 507, 1158]])
I would like to get the array number with the smallest square difference among all its members, the numpythonic version:
for num,item in enumerate(items): #Calculate for each list of items for n in range(len(item)): for i in range(n, len(item)): dist += (item[n]-item[i])**2 #Key formula if dist>min_dist: #This is a shortcut break else: continue break if min_dist is None or dist < min_dist: min_dist = dist best = num #We get the number of the combination we want
I would be grateful for any tips.