I have two numpy arrays with three dimensions (3 x 4 x 5) and I want to concatenate them so the result has four dimensions (3 x 4 x 5 x 2). In Matlab, this can be done with
How about the following:
c = concatenate((a[:,:,:,None],b[:,:,:,None]), axis=3)
This gives a (3 x 4 x 5 x 2) array, which I believe is laid out in the manner you require.
Here, None is synonymous to np.newaxis: Numpy: Should I use newaxis or None?
edit As suggested by @Joe Kington, the code could be cleaned up a little bit by using an ellipsis:
c = concatenate((a[...,None],b[...,None]), axis=3)