I have a math problem about Mathematica, I am looking help from you. I hope that you could help me.
The Math Problem:
list= { {0,0,1},{1,0,0},{0,1,0} ,{1,2,3}};
as you know that list is a List,
and the first three elements of the list is list[[1]]、list[[2]]、list[[3]].
but the three elements of list[[1]]、list[[2]]、list[[3]] are all the same, that is 1,0,0.
the only difference is their order.
So I need a function to deal with the List:
The Results must been
p={{0,0,1} ,{1,2,3}}
(also can been p={{1,0,0} ,{1,2,3}},etc).
I know two functions can do that:
(1)
p = DeleteDuplicates [ list, Sort[#1] == Sort[#2] & ];
(2)
p = Union[list, SameTest -> (SameQ[Sort[#1], Sort[#2]] &) ]
when List has 100,000 elements (Length[list]=100,000) , the speeds of these two functions
are too slow(It takes me a day, but has no results).
eg
list={};
For[i=1,i<=100000,i++,
list=Append[list,{0,0,Random[Integer,{1,5}]}]
];
p = DeleteDuplicates [ list, Sort[#1] == Sort[#2] & ];
Could you help me or give some suggestions ?
DeleteDuplicates[Sort /@ set]– Mr.Wizard Jul 18 '14 at 12:39GatherByrather thanDeleteDuplicateswith a custom comparator, so you want:First /@ GatherBy[set, Sort]. The reason why is explained in my answer there. – Mr.Wizard Jul 18 '14 at 12:49ForandAppend. Also,Randomis deprecated; you should useRandomInteger,RandomRealetc. This is not just syntax; they produce higher quality pseudorandom numbers. Yourlistcould be built with:list = RandomInteger[{1, 5}, {40000, 3}];. Faster, better, and a lot easier to write. :-) – Mr.Wizard Jul 18 '14 at 13:43list2. What does your actual data look like? Also I think it would be better to post this (Question2) separately, along with the more realistic example data. For general use I doubtIntersectioncan be greatly improved upon, however for certain data there are interesting options such as bit-masks. – Mr.Wizard Jul 21 '14 at 08:20list2=BoundaryPtsIndex;
– YuYong Jul 21 '14 at 08:53