I have an array:
test_arr = np.array([ [1.2, 2.1, 2.3, 4.5],
[2.6, 6.4, 5.2, 6.2],
[7.2, 6.2, 2.5, 1.7],
[8.2, 7.6, 4.2, 7.3] ]
Is it possible to obtain a pandas dataframe of the form:
row_id | row1 | row2 | row3 | row4
row1 0.0 d(row1,row2) d(row1,row3) d(row1,row4)
row2 ... 0.0 ... ...
row3 ... ... 0.0 ...
row4 ... ... 0.0 ...
where d(row1, row2)
is the Euclidean distance between row1
and row2.
What I am trying now is first generating a list of all pairs of rows, then computing the distance and assigning each element to the dataframe. Is there a better/faster way of doing this?