Let's say we have a matrix (or an arbitrary 2+D list) x and an integer vector l of the same length. What is the most elegant way to get a list {x[[1,l[[1]]]], x[[2, l[[2]]]],...}? The best solution I can think about is
x[[#, l[[#]]]]&/@Range@Length@x , but I'm sure there should be a much easier/more elegant way.
xis an arbitrary matrix, e.g.x = RandomReal[{0., 1.}, {3, 3}].lis a list of integers with the same length asx, e.g.l={1,2,2}. Yes, this additional condition is required if we want the code to be evaluated without errors. $\endgroup$