np hstack

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

showing results for - "np hstack"
Irene
19 Jul 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
Lorena
24 May 2018
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]]
Anna
10 Aug 2016
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