python np.hstack

gz153016發表於2020-12-23
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
# print('np.vstack((arr1, arr2)):', np.vstack((arr1, arr2)))
print('np.hstack((arr1, arr2)):', np.hstack((arr1, arr2)))
# np.hstack((arr1, arr2)): [1 2 3 4 5 6]


a1 = np.array([[1, 2], [3, 4], [5, 6]])
a2 = np.array([[7, 8], [9, 10], [11, 12]])
# print('a1:', a1)
# print('a2:', a2)
print("np.hstack((a1, a2)):", np.hstack((a1, a2)))
'''
np.hstack((a1, a2)): [[ 1  2  7  8]
 [ 3  4  9 10]
 [ 5  6 11 12]]

'''

相關文章