The anatomy of an ndarray in NumPy looks like this red cube below: (source: Physics Dept, Cornell Uni)


Once you leave the 2D space and enter 3D or higher dimensional spaces, the concept of rows and columns doesn't make much sense anymore. But still you can intuitively understand 3D arrays. For instance, considering your example:

In [41]: b
Out[41]: 
array([[[ 1,  2,  3],
        [ 4,  5,  6]],

       [[ 7,  8,  9],
        [10, 11, 12]]])

In [42]: b.shape
Out[42]: (2, 2, 3)

Here the shape of b is (2, 2, 3). You can think about it like, we've two (2x3) matrices stacked to form a 3D array. To access the first matrix you index into the array b like b[0] and to access the second matrix, you index into the array b like b[1].

# gives you the 2D array (i.e. matrix) at position `0`
In [43]: b[0]
Out[43]: 
array([[1, 2, 3],
       [4, 5, 6]])


# gives you the 2D array (i.e. matrix) at position 1
In [44]: b[1]
Out[44]: 
array([[ 7,  8,  9],
       [10, 11, 12]])

However, if you enter 4D space or higher, it will be very hard to make any sense out of the arrays itself since we humans have hard time visualizing 4D and more dimensions. So, one would rather just consider the ndarray.shape attribute and work with it.


More information about how we build higher dimensional arrays using (nested) lists:

For 1D arrays, the array constructor needs a sequence (tuple, list, etc) but conventionally list is used.

In [51]: oneD = np.array([1, 2, 3,])    
In [52]: oneD.shape
Out[52]: (3,)

For 2D arrays, it's list of lists but can also be tuple of lists or tuple of tuples etc:

In [53]: twoD = np.array([[1, 2, 3], [4, 5, 6]])
In [54]: twoD.shape
Out[54]: (2, 3)

For 3D arrays, it's list of lists of lists:

In [55]: threeD = np.array([[[1, 2, 3], [2, 3, 4]], [[5, 6, 7], [6, 7, 8]]])

In [56]: threeD.shape
Out[56]: (2, 2, 3)

P.S. Internally, the ndarray is stored in a memory block as shown in the below picture. (source: Enthought)

Answer from kmario23 on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › best way to visualize a 3d numpy array?
r/learnpython on Reddit: Best way to visualize a 3d numpy array?
February 24, 2023 -

I have a 3d numpy array where the indices of each element represent the coordinates in the cartesian system and the value of each element represents something, let's say temperature. What would be the optimal way to visualize the temperature distribution in this space?

I have been looking at the 3d scatterplot approach in matplotlib, but I can't really make it work. Could someone point me in the right direction? Thanks!

🌐
Medium
medium.com › @NavSpeak › making-sense-of-numpy-axes-how-to-visualize-arrays-in-3d-13474aeaeca4
Making Sense of NumPy Axes: How to Visualize Arrays in 3D | by Navspeak | Medium
November 13, 2025 - A true RGB image can be represented as 3D numpy array with shape as: ... from PIL import Image import numpy as np arr = np.random.randint(0, 256, (40, 40, 3), dtype=np.uint8) arr[:, :, 0] = 0 # Red channel arr[:, :, 1] = 255 # Green channel arr[:, :, 2] = 0 # Blue channel img = Image.fromarray(arr) img # a green cube · We could perform operations along axes. An example: ... When it comes to 4D or higher, direct visualization becomes impossible — our brains evolved in a 3D world!
Discussions

python - Very Basic Numpy array dimension visualization - Stack Overflow
I'm a beginner to numpy with no experience in matrices. I understand basic 1d and 2d arrays but I'm having trouble visualizing a 3d numpy array like the one below. How do the following python lists... More on stackoverflow.com
🌐 stackoverflow.com
python - Visualizing a 3d numpy array of 1's and 0's - Stack Overflow
Alright so guys I have this 3d array of 1's and 0's which is supposed to represent a 3d object. 0 means that there is nothing there. 1 means that the objects exists in that co-ordinate. I need to d... More on stackoverflow.com
🌐 stackoverflow.com
June 29, 2017
Python visualising 3D numpy arrays - Stack Overflow
I am looking to visualize some 3D numpy arrays in a similar manner I would do it with pyplot.imshow with 2D array. It looks like the best option would be to use the mayavi package. Unfortunately, ... More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
python - Creating a 3D plot from a 3D numpy array - Stack Overflow
Ok, so I feel like there should be an easy way to create a 3-dimensional scatter plot using matplotlib. I have a 3D numpy array (dset) with 0's where I don't want a point and 1's where I do, basica... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Arrayviz
arrayviz.com
Interactive 3D Array Visualizer | JSON, CSV & NumPy Matrix Viewer
A free, browser-based 3D array visualizer. Transform multidimensional arrays, JSON, CSV, and NumPy matrices into interactive 3D visualizations for debugging and data science.
Author: loijord
Top answer
1 of 1
33

The anatomy of an ndarray in NumPy looks like this red cube below: (source: Physics Dept, Cornell Uni)


Once you leave the 2D space and enter 3D or higher dimensional spaces, the concept of rows and columns doesn't make much sense anymore. But still you can intuitively understand 3D arrays. For instance, considering your example:

In [41]: b
Out[41]: 
array([[[ 1,  2,  3],
        [ 4,  5,  6]],

       [[ 7,  8,  9],
        [10, 11, 12]]])

In [42]: b.shape
Out[42]: (2, 2, 3)

Here the shape of b is (2, 2, 3). You can think about it like, we've two (2x3) matrices stacked to form a 3D array. To access the first matrix you index into the array b like b[0] and to access the second matrix, you index into the array b like b[1].

# gives you the 2D array (i.e. matrix) at position `0`
In [43]: b[0]
Out[43]: 
array([[1, 2, 3],
       [4, 5, 6]])


# gives you the 2D array (i.e. matrix) at position 1
In [44]: b[1]
Out[44]: 
array([[ 7,  8,  9],
       [10, 11, 12]])

However, if you enter 4D space or higher, it will be very hard to make any sense out of the arrays itself since we humans have hard time visualizing 4D and more dimensions. So, one would rather just consider the ndarray.shape attribute and work with it.


More information about how we build higher dimensional arrays using (nested) lists:

For 1D arrays, the array constructor needs a sequence (tuple, list, etc) but conventionally list is used.

In [51]: oneD = np.array([1, 2, 3,])    
In [52]: oneD.shape
Out[52]: (3,)

For 2D arrays, it's list of lists but can also be tuple of lists or tuple of tuples etc:

In [53]: twoD = np.array([[1, 2, 3], [4, 5, 6]])
In [54]: twoD.shape
Out[54]: (2, 3)

For 3D arrays, it's list of lists of lists:

In [55]: threeD = np.array([[[1, 2, 3], [2, 3, 4]], [[5, 6, 7], [6, 7, 8]]])

In [56]: threeD.shape
Out[56]: (2, 2, 3)

P.S. Internally, the ndarray is stored in a memory block as shown in the below picture. (source: Enthought)

🌐
Learn By Visualize
learnbyvisualize.com › visualizer
NumPy Array Visualizer
Interactive 3D visualization of NumPy arrays to understand multi-dimensional data structures
Find elsewhere
🌐
YouTube
youtube.com › guillermo barbadillo
Numpy 3d array visualization with Paraview - YouTube
Example of how to visualize 3d arrays with Paraview. 1. Save the 3d array to vtr file. You can follow the instructions of this link. https://www.kaggle.com/i...
Published: July 22, 2017
Views: 4K
🌐
StudyRaid
app.studyraid.com › en › read › 14674 › 503347 › visualizing-3d-numpy-arrays-with-surface-plots
Understand visualizing 3D NumPy arrays with surface plots
To visualize 3D NumPy arrays, use Matplotlib's mplot3d toolkit. A surface plot requires a 2D grid of (X,Y) coordinates and corresponding Z-values stored in a NumPy array.
🌐
TutorialsPoint
tutorialspoint.com › article › creating-a-3d-plot-in-matplotlib-from-a-3d-numpy-array
Creating a 3D plot in Matplotlib from a 3D numpy array
May 15, 2021 - import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Set figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create figure and 3D axis fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Create random 3D data data = np.random.random(size=(3, 3, 3)) # Extract coordinates where data is non-zero z, x, y = data.nonzero() # Create 3D scatter plot ax.scatter(x, y, z, c=z, alpha=1) # Add labels ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') plt.show()
🌐
Stack Overflow
stackoverflow.com › questions › 23165371 › python-visualising-3d-numpy-arrays
Python visualising 3D numpy arrays - Stack Overflow
May 24, 2017 - If you are interested in slicing your 3D np.ndarray and looking at cuts of the volume along the 3 axes, then a very simple tool, based on matplotlib, is PyNax. It allows you to visualize 3 orthogonal cuts of your data (along the three array axes) with interactive navigation through these cuts.
Top answer
1 of 2
33

If you have a dset like that, and you want to just get the 1 values, you could use nonzero, which "returns a tuple of arrays, one for each dimension of a, containing the indices of the non-zero elements in that dimension.".

For example, we can make a simple 3d array:

>>> import numpy
>>> numpy.random.seed(29)
>>> d = numpy.random.randint(0, 2, size=(3,3,3))
>>> d
array([[[1, 1, 0],
        [1, 0, 0],
        [0, 1, 1]],

       [[0, 1, 1],
        [1, 0, 0],
        [0, 1, 1]],

       [[1, 1, 0],
        [0, 1, 0],
        [0, 0, 1]]])

and find where the nonzero elements are located:

>>> d.nonzero()
(array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2]), array([0, 0, 1, 2, 2, 0, 0, 1, 2, 2, 0, 0, 1, 2]), array([0, 1, 0, 1, 2, 1, 2, 0, 1, 2, 0, 1, 1, 2]))
>>> z,x,y = d.nonzero()

If we wanted a more complicated cut, we could have done something like (d > 3.4).nonzero() or something, as True has an integer value of 1 and counts as nonzero.

Finally, we plot:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, -z, zdir='z', c= 'red')
plt.savefig("demo.png")

giving

2 of 2
1

If you wanted to avoid using the nonzero option (for example, if you had a 3D numpy array whose values were supposed to be the color values of the data points), you could do what you do, but save some lines of code by using ndenumerate.

Your example might become:

for index, x in np.ndenumerate(dset):
    if x == 1:
        ax.scatter(*index, c = 'red')

I guess the point is just that you dont need to have nested for loops to iterate through multidimensional numpy arrays.

🌐
Terbium
terbium.io › 2017 › 12 › matplotlib-3d
Displaying 3D images in Python - Terbium
December 10, 2017 - “Modulation of connectivity in visual pathways by attention: cortical interactions evaluated with structural equation modelling and fMRI.” Cerebral cortex (New York, NY: 1991) 7.8 (1997): 768-778. for cool brain images. Of course, feel free to visualize whatever you want. As long as you have a 3D numpy array of data, you can skip to the next section to get started on the actual visualizing.
🌐
Stack Overflow
stackoverflow.com › questions › 73186596 › visualising-and-understanding-a-3d-array-tensor-in-numpy-matplotlib
python - Visualising and Understanding a 3D Array / Tensor in Numpy / Matplotlib - Stack Overflow
To better visualise this array I have created a plot: Copyplt.rcParams["figure.figsize"] = [18.00, 14.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') data = sdf z, x, y = data.nonzero() ax.scatter(x, y, z, c=z, alpha=1) ax.plot(x, y, z, label='3D Array of Shape: (57, 90, 128)') ax.legend(fontsize=25) ax.set_xlabel('$Rows$', fontsize=20) ax.set_ylabel('$Columns$', fontsize=20) ax.set_zlabel('$Order layers$', fontsize=20) plt.show()
🌐
Jay Alammar
jalammar.github.io › visual-numpy
A Visual Intro to NumPy and Data Representation – Jay Alammar – Visualizing machine learning one concept at a time.
June 26, 2019 - Note: Keep in mind that when you print a 3-dimensional NumPy array, the text output visualizes the array differently than shown here. NumPy’s order for printing n-dimensional arrays is that the last axis is looped over the fastest, while the first is the slowest.
🌐
Kaggle
kaggle.com › questions-and-answers › 449166
How to show the structure of 3d numpy array in python | Kaggle
Hello everyone. I was wondered to know how we can plot 3d numpy arrays in python. Like this I mean the way we can see this image, we can plot it. Thanks
🌐
YouTube
youtube.com › watch
05 NymPy | Numerical Python | 3-Dimensional Image Array Manipulation: AI and ML Foundations - YouTube
In this lesson, Joed Goh explain how to use some of the useful functions of numpy library to manipulate numerical data. This also covers the use of matplotli...
Published: June 20, 2021