I want to "join" two 2-dimensional numpy arrays of same shape to create a dimensional numpy array. I can easily do this using loop but I am looking for faster way. Here is the toy example. The two numpy arrays are:
data1 = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]])
data2 = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]])*100
data1
> array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]])
data2
> array([[ 100, 200, 300, 400, 500],
[ 600, 700, 800, 900, 1000],
[1100, 1200, 1300, 1400, 1500]])
Both have a shape (3,5). I want to create (3,5,2) shape numpy array. That is:
data3 = []
for irow in range(data1.shape[0]):
data3_temp = []
for icol in range(data1.shape[1]):
data3_temp.append([data1[irow,icol],
data2[irow,icol]])
data3.append(data3_temp)
data3 = np.array(data3)
data3.shape
> (3, 5, 2)
data3
>array([[[ 1, 100],
[ 2, 200],
[ 3, 300],
[ 4, 400],
[ 5, 500]],
[[ 6, 600],
[ 7, 700],
[ 8, 800],
[ 9, 900],
[ 10, 1000]],
[[ 11, 1100],
[ 12, 1200],
[ 13, 1300],
[ 14, 1400],
[ 15, 1500]]])
Please let me know.