I have to analyze a quadratic 2D numpy array LL for values which are symmetric (LL[i,j] == LL[j,i]) and not zero.
Is there a faster and more "array like" way without loops to do this? Is there a easy way to store the indices of the values for later use without creating a array and append the tuple of the indices in every loop?
Here my classical looping approach to store the indices:
IdxArray = np.array() # Array to store the indices
for i in range(len(LL)):
for j in range(i+1,len(LL)):
if LL[i,j] != 0.0:
if LL[i,j] == LL[j,i]:
IdxArray = np.vstack((IdxArray,[i,j]))
later use the indices:
for idx in IdxArray:
P = LL[idx]*(TT[idx[0]]-TT[idx[1]])
...