Answers for "vstack and hstack in numpy"

6

np.hstack

# np.hstack concatenates arrays column-wise

a = np.array([1], [2], [3]) #read as a vector, i.e. a column
b = np.array([4], [5], [6]) #read as a vector, i.e. a column 
							#concatenated to the first one
c = np.hstack((a, b)))
print(c)
# output is
# [[1, 4],
#  [2, 5],
#  [3, 6]]
Posted by: Guest on June-30-2020
0

vstack numpy

>>> a = np.array([[1], [2], [3]])
>>> b = np.array([[4], [5], [6]])
>>> np.vstack((a,b))
array([[1],
       [2],
       [3],
       [4],
       [5],
       [6]])
Posted by: Guest on July-03-2021

Python Answers by Framework

Browse Popular Code Answers by Language