I have two lists of sublists. The sublists in the first list contain three elements while the points in the second list contain four e.g.:
list3dim={{1.3,0.1, 140.0},{1.4,0.1,140.0},...};
list4dim={{1.2,0.1, 140.0,5.13},{1.4,0.1,140.0,6.34},...};
I want to select the sublists in the list4dim where the first three elements are a sublist of listdim3. For the example the result should be:
{{1.4,0.1,140.0,6.34},...}
So far I found a slow solution by using MemberQ:
SelectOverlap[list4dim_, list3dim_] :=
Select[list4dim, MemberQ[list3dim[[All,1 ;; 3]], #[[1;;3]]] &]
My question is if there is a faster way to do this because my lists are very long.
Answer:
as pointed out by Jason B. and in reference to paw this solution gives the best performance so far:
SelectOverlap =
Compile[{{list4dim, _Real, 2}, {list3dim, _Real, 2}},
Select[list4dim, MemberQ[list3dim[[All, 1 ;; 3]], #[[1 ;; 3]]] &]];
list4dim
and a subset list inlist3dim
will have the same position, or can they be scrambled? $\endgroup$