If I had two Numpy arrays: both with shape (50,5,5) how would I add both of them to get an array with (50,5,10)?
2 Answers
Use concatenate:
import numpy as np
n = 50 * 5 * 5
a = np.random.random(size=n).reshape(50,5,5)
b = np.random.random(size=n).reshape(50,5,5)
np.concatenate([a,b], axis=2).shape # (50, 5, 10)
Comments
numpy.dstack would do the trick
import numpy
In[2]: out_array = numpy.dstack([numpy.empty((50, 5, 5)), numpy.empty((50, 5, 5))])
In[3]: out_array.shape
Out[3]: (50L, 5L, 10L)