Site icon DataFlair

NumPy Joining Array

Machine Learning courses with 110+ 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)

 

Exit mobile version