Im trying to escape doing double loops given the large number of items in the arrays.
I have two list with a format like this:
list1={{1,2,0},{1,3,0},{4,6,0},{2,3,0}} (*Third element of each item is 0*)
list2={{3,2,1},{1,3,1},{4,5,1}} (*Third element of each item is 1*)
List might not be of equal length.
If the first two elements of a list match I want to replace that item in list1
with the corresponding item in list2
.
result={{1,2,0},{1,3,1},{4,6,0},{2,3,0}}
Since there seems to be confusion I'll provide another example:
test1={{0.5,0.5,0},{1,1,0},{1.5,1.5,0},{2.0,2.0,0}};
test2={{0.5,0.5,1},{2.0,2.0,1}};
The results should then be:
result={{0.5,0.5,1},{1,1,0},{1.5,1.5,0},{2.0,2.0,1}};
Which includes every item in test1
.
I am sorry if its confusing, this is my first post here.
I have this setup but it takes too much time:
densitydata = Reap[Do[If[{cross[[m, 1]],cross[[m, 2]]} == {fullzone0[[n,1]] = fullzone0[[n, 2]]},
Sow[cross[[m]]], Sow[fullzone0[n]]],
{n, 1,Dimensions[fullzone0][[1]]}, {m, 1,Dimensions[cross][[1]]}]][[2]][[1]];