1
$\begingroup$

I have a list of vectors:

v={{{0,0,0},{0,0,1},{1,1,0}},

{{1,0,0},{1,1,1},{0,1,1}},

{{0,0,1},{0,0,0},{1,1,0}}}

Clearly, the first entry and the third entry contain the same vectors. I want to delete one of the duplications but I am not sure how to do this.

I can tell that there is a duplication from

DuplicateFreeQ[v]

which returns True

However, any of the ways that I know how to delete duplicate cases involve having at least 2 different sets. I am not sure how to do this internally?

I tried using DeleteCases and OrderlessPatternSequence but I cannot seem to get it to look through the elements of v and delete duplicate lists that have the same vectors in different orders?

The only thing I can do is

If[MatchQ[Sort[v[[1]]],Sort[v[[3]]],Join[{v[[1]]},{v[[2]]]},v]

Which is pretty useless as I'd have to check through each of the rows manually and Join the non-dduplicate rows manually.

Any hints/tips/suggestions welcome. Thanks!

$\endgroup$
1
  • 1
    $\begingroup$ DeleteDuplicates[Sort /@ v] $\endgroup$
    – MelaGo
    Sep 19, 2023 at 16:17

2 Answers 2

2
$\begingroup$

You could just use Union:

Union[Sort /@ v]

You could also use DeleteDuplicatesBy:

DeleteDuplicatesBy[v, Sort]
$\endgroup$
1
$\begingroup$

Another way to do this using GatherByand Union:

GatherBy[Map[Union, v], Union][[All, 1]]

(*{{{0, 0, 0}, {0, 0, 1}, {1, 1, 0}}, {{0, 1, 1}, {1, 0, 0}, {1, 1, 1}}}*)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.