I have a very basic question regarding to arrays in numpy, but I cannot find a fast way to do it. I have three 2D arrays A,B,C with the same dimensions. I want to convert these in one 3D array (D) where each element is an array
D[column][row] = [A[column][row] B[column][row] c[column][row]]
What is the best way to do it?
You can use numpy.dstack:
numpy.dstack stack the array along the third axis, so, if you stack 3 arrays (
a
,b
,c
) of shape(N,M)
, you'll end up with an array of shape(N,M,3)
.An alternative is to use directly:
That gives you a
(3,N,M)
array.What's the difference between the two? The memory layout. You'll access your first array
a
asor