1

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?

2

2 Answers 2

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)

Sign up to request clarification or add additional context in comments.

Comments

0

Hey you can have a look at the below link to resolve your issue

Concat two arrays of different dimensions numpy

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.