Could you explain the comparison inside your model a bit?
I.e. if you pass two batches of indices [0, 1, 2] and [0, 1, 2], will the model output the scalars for 0-0, 1-1, 2-2` or will it also compute all other combinations?
In the former case, you could increase the inner batch (j) by one while increasing the outer batch by batch_size.



 sudddddd:

I also want to know if there is a method to avoid duplicate comparisons as out matrix is symmetric.


You could add a check for the indices as:
for index_i, i in enumerate(A):
    temp = []
    for index_j, j in enumerate(B):
        if j > i: # or j >= i, if you don't want to compare the same indices
            continue