Consider the following two grids:
grid1 = RandomReal[{0, 1}, {3, 2}];
grid2 = Flatten[Thread[{#[[1]], #[[2]], Range[3]}] & /@ grid1, 1];
Therefore, grid2
is grid1
but with additional coordinate.
Next, consider the tables of values of two functions func1
, func2
on grid1
, grid2
:
func1[x_,y_]=Exp[-x]*Cos[y];
func2[x_,y_,z_]=Exp[-x^2]Sin[y]/z;
vals1 = Join[grid1, {func1[#[[1]],#[[2]]]} & /@ grid1, 2];
vals2 = Join[grid2, {func2[#[[1]],#[[2]],#[[3]]]} & /@ grid2,
2];
I want to obtain the table
table=Join[grid2,{func1[#[[1]],#[[2]]]*func2[#[[1]],#[[2]],#[[3]]]}&/@grid2,2]
assuming that I do not know func1
, func2
, i.e., having pre-computed vals1
, vals2
.
Could you please tell me how to do this quickly (in reality, vals1
, vals2
are large multi-dimensional datasets)?
Join[grid2, List /@ Flatten[vals1[[All, -1]] Partition[vals2[[All, -1]], 3]], 2]
? $\endgroup$