NumPy Joining Array

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

# How to merge two array
# concatenate(),stack(),hstack(),vstack()
import numpy as np
ar1=np.array([[1,2,3],[4,5,6],[7,8,9]])
ar2=np.array([[10,20,30],[40,50,60],[70,80,90]])
# vstack()  concatenate( axis=0)

print("AR1 Shape: ",ar1.shape)
print("AR2 Shape: ",ar2.shape)
print(ar1)
print()
print(ar2)
ar3=np.vstack((ar1,ar2)) 
print(ar3)
print("AR3 Shape: ",ar3.shape)

# # hstack()  concatenate( axis=1)

# print("AR1 Shape: ",ar1.shape)
# print("AR2 Shape: ",ar2.shape)
# print(ar1)
# print()
# print(ar2)
# ar3=np.hstack((ar1,ar2)) 
# print(ar3)
# print("AR3 Shape: ",ar3.shape)

#stack ()
# print("AR1 Shape: ",ar1.shape)
# print("AR2 Shape: ",ar2.shape)
# print(ar1)
# print()
# print(ar2)
# ar3=np.stack((ar1,ar2),axis=1) # 0-col 1-row
# print("AR3 Shape: ",ar3.shape)
# print(ar3)


# concatenate()
# print(ar1.shape)
# print(ar2.shape)
# print(ar1)
# print()
# print(ar2)
# print()
# #ar3=np.concatenate((ar1,ar2),axis=0) # 0-column 1-axis
# ar3=np.concatenate((ar1,ar2),axis=1) # 0-column 1-axis
# print(ar3)
# print(ar3.shape)

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *