I have three 1D arrays, where two are the same length but the third is a different length, e.g.
A = np.array([1, 2, 3, 4])
B = np.array([10, 20, 30, 40])
C = np.array([100, 200, 300, 400, 500])
I want to combine them into a grid as follows:
D = np.array([[[1, 10, 100], [1, 10, 200], [1, 10, 300], [1, 10, 400], [1, 10, 500]],
[[2, 20, 100], [2, 20, 200], [2, 20, 300], [2, 20, 400], [2, 20, 500]],
[[3, 30, 100], [3, 30, 200], [3, 30, 300], [3, 30, 400], [3, 30, 500]],
[[4, 40, 100], [4, 40, 200], [4, 40, 300], [4, 40, 400], [4, 40, 500]]])
It's similar to a coordinate grid, but where A and B change together, so I assume they need to be combined first, and the resulting 2D array then combined with C somehow, but I can't find the right combination of stack, concatenate, meshgrid, etc.
The real arrays will be much larger than this example (thousands of values each), and the code will be called very many times, so speed is important. It will live in the main loop of an MCMC sampler, where A and B are parameters that vary on each loop, while C is a constant.