I have a 2D array of 2D arrays t, which can be emulated by this code:
import numpy as np
n=3
x = np.random.randint(0,10, (n,1))
y = np.random.randint(0,10, (n,2))
t = np.empty((2,2), object)
t[0,:] = [x,y]
t[1,:] = [x+10,y+10]
How can I merge the t into a single array of size (6,3) like this:
np.vstack([np.hstack([x,y]), np.hstack([x,y])+10])
>Solution :
One sequence that works:
In [88]: [np.hstack(row) for row in t]
Out[88]:
[array([[3, 9, 9],
[1, 1, 0],
[0, 6, 3]]),
array([[13, 19, 19],
[11, 11, 10],
[10, 16, 13]])]
In [89]: np.concatenate([np.hstack(row) for row in t], axis=0)
Out[89]:
array([[ 3, 9, 9],
[ 1, 1, 0],
[ 0, 6, 3],
[13, 19, 19],
[11, 11, 10],
[10, 16, 13]])