New to Mathematica, I have a nested list containing many lists(A) of 16 lists(B) of 3 integers(C). I wish to put in each (Aj, Bi, C2) the result of (Aj, Bi-1, C2)+(Aj, Bi, C1). I could do it with a loop, or a spreadsheet, but is there a more elegant way to do this using functions like Accumulate? I simplified the data here:
myList =
{{{a, b}, {c, d}, {e, f}},
{{g, h}, {i, j}, {k, l}},
{{m, n}, {o, p}, {q, r}},
{{s, t}, {u, v}, {w, x}}}
A simple replacement test function before using values of other elements:
myF[x_] := x*2
ReplacePart[myList, {_, _, 2} -> xx]
Result:
{{{a, xx}, {c, xx}, {e, xx}},
{{g, xx}, {i, xx}, {k, xx}},
{{m, xx}, {o, xx}, {q, xx}},
{{s, xx}, {u, xx}, {w, xx}}}
I tried many expressions in the function without success.
ReplacePart[myList, {_, _, 2} -> myF[ ??? ]]
should result:
{{{a, 2b}, {c, 2d}, {e, 2f}},
{{g, 2h}, {i, 2j}, {k, 2l}},
{{m, 2n}, {o, 2p}, {q, 2r}},
{{s, 2t}, {u, 2v}, {w, 2x}}}
How could Accumulate give this?
{{{a, a}, {c, a+c}, {e, a+c+e}},
{{g, g}, {i, g+i}, {k, g+i+k}},
{{m, m}, {o, m+o}, {q, m+o+q}},
{{s, s}, {u, s+u}, {w, s+u+w}}}
Thanks!
myList.{{1, 0}, {0, 2}}
. Very fast, I think. $\endgroup$