hstack in numpy

Solutions on MaxInterview for hstack in numpy by the best coders in the world

showing results for - "hstack in numpy"
Niklas
15 Sep 2020
1>>> a = np.array((1,2,3))
2>>> b = np.array((2,3,4))
3>>> np.hstack((a,b))
4array([1, 2, 3, 2, 3, 4])
5>>> a = np.array([[1],[2],[3]])
6>>> b = np.array([[2],[3],[4]])
7>>> np.hstack((a,b))
8array([[1, 2],
9       [2, 3],
10       [3, 4]])
11
Paolo
07 May 2017
1# np.hstack concatenates arrays column-wise
2
3a = np.array([1], [2], [3]) #read as a vector, i.e. a column
4b = np.array([4], [5], [6]) #read as a vector, i.e. a column 
5							#concatenated to the first one
6c = np.hstack((a, b)))
7print(c)
8# output is
9# [[1, 4],
10#  [2, 5],
11#  [3, 6]]
Rafael
28 Aug 2017
1>>> a = np.array((1,2,3))
2>>> b = np.array((2,3,4))
3>>> np.hstack((a,b))
4array([1, 2, 3, 2, 3, 4])
5>>> a = np.array([[1],[2],[3]])
6>>> b = np.array([[2],[3],[4]])
7>>> np.hstack((a,b),columns=['hurala','panalal'])
8array([[1, 2],
9       [2, 3],
10       [3, 4]])
11