2

Suppose I have three "sheets" of matrix a,b and c, each with the same mnp dimension. And I want to combine them to get a new mnp*3 matrix whose (i,j,k) element is (a[i,j,k],b[i,j,k],c[i,j,k]). Which command should I use ? The dstack command seems not work here. Thanks.

2 Answers 2

4

Another one liner would be:

result = numpy.array( (a,b,c) ).transpose( (1,2,3,0) )

or a more self-descriptive method:

result = empty( (m,n,p,3) )
result[:,:,:,0] = a
result[:,:,:,1] = b
result[:,:,:,2] = c
Sign up to request clarification or add additional context in comments.

Comments

2

I think what you want is:

np.concatenate([np.expand_dims(x, -1) for x in (a, b, c)], axis=3)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.