Suppose I have two lists:
list1={{-4,10,3},{8,-2,7},{10,-8,-3}, {9,9,-10}, {9,-3,-2}, {-5,-3,5}}
list2={{-4,10,0},{8,-2,-3},{10,-8,-4}, {9,9,10}, {9,-3,1}, {-5,-3,8}}
The goal is to identify elements in each sublist of list1
whose third element is larger than a given criterion, and replace the third element in the corresponding tuple in list2
with $0$.
Let's say the threshold is $1$, then the result would be:
result = {{-4, 10, 0}, {8, -2, 0}, {10, -8, -4}, {9, 9, 10}, {9, -3, 1}, {-5, -3, 0}}
I already have code to solve this, but I am looking for a more efficient way to do this without Do
.
I can achieve the result by using:
out = Reap[Do[If[list1[[n, 3]] > 1, Sow[n], Continue], {n, 1, Dimensions[list1[[1]]}]][[2, 1]];
Do[list2[[out[[s]], 3]] = 0.0, {s, 1, Dimensions[out][[1]]}]
This is good for a small list, however I need an efficient way to do this with approximately 265,000 tuples. It would be a plus to keep something similar to the first step, where the points are identified and stored. The second step can be done on multiple lists, without doing the identifying of the points each time. Any ideas how to improve this ?