concatenating numpy arrays

Travis E. Oliphant oliphant.travis at ieee.org
Tue Oct 31 07:48:25 EST 2006


Rolf Wester wrote:
> Hi,
> 
> I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3) 
> into a single array with shape (n1,n2+n3). I guess there is an elegant 
> way to do this but I couldn't figure it out. So any help is very much 
> appreciated.
> 

Suppose a1.shape is (n1,n2)
and a2.shape is (n1,n3)

Then you want to do

a3 = concatenate((a1,a2),axis=1)

or equivalently

a3 = hstack([a1,a2])

a3 = r_['1',a1,a2]


-Travis






More information about the Python-list mailing list