I have a 2D array and I need to do some analysis on it which involves me performing a calculation for every possible pair of elements and then summing them up.
The problem is that I need to avoid doing the calculation twice for each pair - if I am looking at elements A and B, I need to do the calculation on A*B and avoid repeating it for B*A.
At the moment I am doing it this way:
comb=[]
amo=len(inds)
for m in range(0,amo):
for n in range(m+1,amo):
comb.append([inds[m],inds[n]])
where inds
is a 1d array.