concatenating numpy arrays

R

Rolf Wester

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.

Regards

Rolf
 
T

Travis E. Oliphant

Rolf said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top