TransWikia.com

Concatenating two numpy arrays side by side

Stack Overflow Asked by Bare on December 5, 2021

I need to concatenate two numpy arrays side by side

np1=np.array([1,2,3])
np2=np.array([4,5,6])

I need np3 as [1,2,3,4,5,6] with the same shape, how to achieve this?

2 Answers

Use np.hstack made for this:

np3 = np.hstack((np1,np2))

output:

[1 2 3 4 5 6]

Answered by Ehsan on December 5, 2021

In concatenate you have to pass axis as None

In [9]: np1=np.array([1,2,3])
   ...: np2=np.array([4,5,6])

In [10]: np.concatenate((np1,np2), axis=None)
Out[10]: array([1, 2, 3, 4, 5, 6])

Answered by bigbounty on December 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP