3/19/2019

Python hstack, vstack example code

import numpy as np

#hstack #1
a = np.array((1,2,3))
b = np.array((2,3,4))
print(np.hstack((a,b)))
>
 [1 2 3 2 3 4]

#hstack #2
a = np.array([[1],[2],[3]])
b = np.array([[2],[3],[4]])
print(np.hstack((a,b)))
>
 [[1 2]
 [2 3]
 [3 4]]

#vstack #1
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
print(np.vstack((a,b)))
>
 [[1 2 3]
 [2 3 4]]


#vstack #2
a = np.array([[1], [2], [3]])
b = np.array([[2], [3], [4]])
print(np.vstack((a,b)))
>
[[1]
 [2]
 [3]
 [2]
 [3]
 [4]]

No comments:

Post a Comment