0

I have 2 numpy arrays like this:

    a = [[a,b,c],
         [d,e,f]]
    b = [[g,h,i],
        [k,l,m]]

I want to merge them into another numpy array, something like following:

c = [[[a,g],[b,h],[c,i]],
    [[d,k],[e,l],[f,m]]]

How can I do it?

1 Answer 1

1

You can use the dstack function, i.e.

a = np.array([[1,2,3],
     [4,5,6]])
print(a)
b = np.array([[10,20,30],
    [40,50,60]])
print(b)

c = np.dstack((a,b))
print(c)

which would outputs

[[1 2 3]
 [4 5 6]]
[[10 20 30]
 [40 50 60]]
[[[ 1 10]
  [ 2 20]
  [ 3 30]]

 [[ 4 40]
  [ 5 50]
  [ 6 60]]]
Sign up to request clarification or add additional context in comments.

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.