-1

I just want to sort of clarify for example could I somehow stack a few 2D arrays into an image?

array1=[[0,0,0,0,0]
        [0,7.6,7,7.2,0]
        [0,7.6,7,0,0]
        [0,0,0,0,0]]

array2=[[0,0,0,0,0]
        [0,7.6,7,7.2,0]
        [0,7.6,7,0,0]
        [0,0,0,0,0]]

And then see them in 3D space such as the cube example at link

I haven't really tried much other than trying to make other things using the geeks for geeks code. So any direction at all would be appreciated.

Sam Taylor
  • 37
  • 6
  • The visualization you expect is unclear. In your link this is 3D scatter, in you case you have a defined grid. Can you provide a schematic of what you expect? – mozway Apr 01 '22 at 15:24
  • yes @mozway If you look further down the link at the cube example like I mentioned, its one under the scatter example. I would like to layer it how they do to make the cube. In my case it would be a z-stack received from a microscope of a cell. But I Was just trying to make it as easy as an example as possible. In this example they use an Array of ones basically to make this cube. I am wondering if I can use an array of pixel values to make an image in 3D as well. Does this make sense? – Sam Taylor Apr 01 '22 at 18:27
  • If this is microscopy pictures, why don't you use a dedicated tool like ImageJ? The issue with the cube visualization is that you will only see the external elements – mozway Apr 01 '22 at 18:36

2 Answers2

0

Assuming numpy arrays as input (not python lists), you can use numpy.dstack:

out = np.dstack((array1, array2))

output:

array([[[0. , 0. ],
        [0. , 0. ],
        [0. , 0. ],
        [0. , 0. ],
        [0. , 0. ]],

       [[0. , 0. ],
        [7.6, 7.6],
        [7. , 7. ],
        [7.2, 7.2],
        [0. , 0. ]],

       [[0. , 0. ],
        [7.6, 7.6],
        [7. , 7. ],
        [0. , 0. ],
        [0. , 0. ]],

       [[0. , 0. ],
        [0. , 0. ],
        [0. , 0. ],
        [0. , 0. ],
        [0. , 0. ]]])

Although, if you want to plot, it might be easier to have a list of the arrays and loop.

mozway
  • 194,879
  • 13
  • 39
  • 75
  • I have seen the np.stack, however I guess I did not word my question well enough. Is there a way to then see an image of this array in three dimensional space, such as the cube example in my link? – Sam Taylor Apr 01 '22 at 16:24
  • What would the color be? – mozway Apr 01 '22 at 17:05
  • The color in particular does not matter right now. But if I could do it even in greyscale that would be a great step in the right direction. @mozway – Sam Taylor Apr 01 '22 at 18:29
  • I won't be able to have a look now, but there are ways using a meshgrid – mozway Apr 01 '22 at 18:38
  • Ok, I can look into meshgrid – Sam Taylor Apr 01 '22 at 18:38
  • @Sam check this previous [answer](https://stackoverflow.com/a/69487097/16343464) of mine, but this is probably only practical with small 3D arrays if you want to be able to see something – mozway Apr 01 '22 at 18:43
0

I believe that you are looking for something like this. I am representing the depth dimension with different colors and an added depth of +z

A = np.array([ [*array1],[*array2] ])
ax = plt.axes(projection='3d')
z_c = ['k','blue']
[ax.scatter(z+A[z,y,x], y, x, c=z_c[z]) for z in range(A.shape[0]) \
 for y in range(A.shape[1]) for x in range(A.shape[2])]

enter image description here