import numpy as np
arr_keys = np.array(np.mat('2 3 1 0; 3 3 3 1'))
arr_rand1 = np.random.rand(2, 4)
arr_rand2 = np.random.rand(2, 4)
arr_final = np.zeros((5, 2, 4))
I want to create a numpy array called arr_final of shape (100, 2, 4) where 100 can be thought to correspond to time and 2, 4 are number of rows and columns respectively
To fill arr_final, I want to use the following logic:
For each grid cell in
arr_final, look up value in corresponding position inarr_keys, lets call itval_alphaFill
arr_finalusing values fromarr_rand1upto theval_alphaposition, and using values fromarr_rand2after that
This can be done using a for loop but is there a more pythonic solution?
--EDIT:
Here's the for loop soln:
for (i, j, k), value in np.ndenumerate(arr_final):
val_alpha = arr_keys[j][k]
arr_final[:val_alpha, j, k] = arr_rand1[j, k]
arr_final[val_alpha:, j, k] = arr_rand2[j, k]