Unique symmetrical elements Numpy Array

Viewed 44

I have a Numpy array as this:

 [1 4]
 [2 3]
 [3 0]
 [4 1]
 [5 6]
 [6 5]
 [7 6]]

This is output of NearestNeighbors algorithm of scikit-learn. I want to remove duplicated values. To have something like this:

[[0 3]
 [1 4]
 [2 3]
 [6 5]
 [7 6]]

I searched a lot, but not found any solution.

1 Answers

One way with sorting and np.unique -

np.unique(np.sort(a, axis=1), axis=0)
Related