Search code examples
pythonnumpytheano

numpy stack rows of ndarray


I have a ndarray A of shape (u,v,w) like this:

  [[[ 1.,  1.,  0.],
    [ 1.,  3.,  0.]],

   [[ 0.,  0.,  0.],
    [ 0.,  0.,  0.]]]

I need to stack the rows (along dimension 0) together like so.

[[1.,   1.,   0.,   0.,   0.,   0.],
 [1.,   3.,   0.,   0.,   0.,   0.]]

How do I do this? I know that if there are only two rows I can do np.hstack((a[0], a[1])) but is there any way to do this without converting the rows into a tuple? I want to use this code in theano (because numpy and theano work similarly)


Solution

  • This shoul work fine:

    np.hstack(a)
    

    Btw a[0], a[1], ... are the rows and not columns of a.