0

I have two numpy arrays which I have to join them side-by side, for example one has a shape of (100,1,300,1) and another one has a shape of (100,1,400,1), the output shape should be (100,1,700,1). I have written below codes but I need to join both np_predict and np_predict_borders as the way I told

np_predict = model.predict(np.array(images))
np_predict=np_predict.reshape(np_predict.shape[0],1,np_predict.shape[1],1)

np_predict_e=model.predict(np.array(images_e))
np_predict_e = np_predict_e.reshape(np_predict_e.shape[0], 1, np_predict_e.shape[1], 1)

I am not sure what command I have to use in numpy to join them?

1
  • 1
    You have the command in your title. Commented Feb 22, 2021 at 8:57

2 Answers 2

1

Use np.concatenate, in axis parameter you define direction of concatenation.

>>> import numpy as np
>>> a = np.zeros((100,1,300,1))
>>> b = np.zeros((100,1,400,1))
>>> c = np.concatenate((a,b),axis=2)
>>> c.shape
(100, 1, 700, 1)
Sign up to request clarification or add additional context in comments.

2 Comments

Can you explain what is the direction of concatenations, and what are axis=0,1, or 2?
@Mah "The axis along which the arrays will be joined", you can understand this as dimmension, your array have 4 dim, so if you want to concat at 3rd dim, you type axis=2
0

You can do this in many ways with numpy. One possibility is using np.dstack:

import numpy as np


A=np.zeros((100,1,300,1))
B = np.ones((100,1,400,1))
C = np.dstack((A,B))
print(C.shape)

output:

(100, 1, 700, 1)

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.