Combining each row from two arrays into one

Let's say I have two arrays a and b.

a.shape is (95, 300)
b.shape is (95, 3)

How can I get a new c array by combining each of 95 lines?

c.shape is (95, 303)
+4
source share
1 answer

IIUC, you can use hstack:

>>> a = np.ones((95, 300))
>>> b = np.ones((95, 3)) * 2
>>> a.shape
(95, 300)
>>> b.shape
(95, 3)
>>> c = np.hstack((a,b))
>>> c
array([[ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       ..., 
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.],
       [ 1.,  1.,  1., ...,  2.,  2.,  2.]])
>>> c.shape
(95, 303)
+3
source

Source: https://habr.com/ru/post/1535781/


All Articles