I do have two arrays which are (150,1400,1200) and (150,1400). I want to know how to combine these two arrays row and column wise in Python?
Asked
Active
Viewed 112 times
1
-
One way to combine the two arrays row-wise is to use the NumPy module's hstack() function. Documentation: https://numpy.org/doc/stable/reference/generated/numpy.hstack.html – Adrian Rudy Dacka Dec 12 '22 at 16:48
-
Can you provide the expected output? – codester_09 Dec 12 '22 at 16:49
2 Answers
3
IIUC, You need to add one dimension to b
then use numpy.concatenate
a = np.random.rand(150, 1400, 1200)
print('a.shape:',a.shape)
b = np.random.rand(150, 1400)
print('b.shape:',b.shape)
print('b[..., None].shape:',b[..., None].shape)
c = np.concatenate([a, b[..., None]], axis=2)
print('c.shape:',c.shape)
Output:
a.shape: (150, 1400, 1200)
b.shape: (150, 1400)
b[..., None].shape: (150, 1400, 1)
c.shape: (150, 1400, 1201)

I'mahdi
- 23,382
- 5
- 22
- 30