Вариант вашего подхода repeat
и reshape
:
In [89]: x = [1, 2, 3]
...: y = [[4, 5], [6, 7], [8, 9]]
In [90]: res = np.zeros((3,2,2),int)
In [91]: res[:,:,1]=y
In [92]: res[:,:,0]=np.array(x)[:,None]
In [93]: res
Out[93]:
array([[[1, 4],
[1, 5]],
[[2, 6],
[2, 7]],
[[3, 8],
[3, 9]]])
In [94]: res.reshape(6,2)
Out[94]:
array([[1, 4],
[1, 5],
[2, 6],
[2, 7],
[3, 8],
[3, 9]])
Он использует broadcasting
для отображения x
и y
в массив res
.