I have two arrays
x * 2
x * 4
where
x = np.ones([5,4],int)
I want to create an array U such that
U = np.empty([5,2,4])
U[:,0,:] = x * 2
U[:,1,:] = x * 4
but I wish to do this automatically (in particular without for loops). Ideally with a one line command like
U[:,?,:] = x * ?
Is there something to substitute to ? to make it work? It is important to avoid both to insert the objects manually and the for loops. This because this is a toy model of something much bigger. With huge numbers for loops take too much time.
Thanks.
np.dstack([x * 2, x * 4]).swapaxes(1,2), with a lot of guessing about the invariants of the problem.