Many thanks @kbisikalo for validating my answer. My pleasure to help.
Besides the Similarity problem and concerning your implementation, I’m glad the column aggregator could help too. By the way, a distance matrix is symetric, so another thing you could try is to use the information directly from every column of the matrix since it is the same as in the rows. Then you could do groupby without the need of transposing. I would take the split collection node out of the counting loop too (split the whole matrix only once) and I would use a “Chunk Loop” (set to one row at a time) or a “Column List” Loop to provide a column at a time, depending on whether you want to group by rows (groupby) or by columns (Column Aggregator). This should improve time execution too.
Hope this helps too
Best
Ael