0

I have Nx3 numpy array, let say:

a=[[1,1,1],[1,2,3],...,[2,1,3],[2,2,2]]

In my case, I don't care about the position of the elements in my "sub 3D array" and I consider them as duplicates:

[1,2,3] == [2,1,3] == [3,1,2] = ...

I would like to delete these duplicates and so get:

a_new = [[1,1,1],[1,2,3],...,[2,2,2]]

The problem is that I have no idea how to do this job.

Any help are welcome and thanks in advance :)

1 Answer 1

2

Use sort and unique:

import numpy as np
a=np.array([[1,1,1],[1,2,3],[2,1,3],[2,2,2]])
np.unique(np.sort(a, axis=1), axis=0)

array([[1, 1, 1],
       [1, 2, 3],
       [2, 2, 2]])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.