You have a truncated array representation. Let's look at a full example:

>>> a = np.zeros((2, 3, 4))
>>> a
array([[[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.]],

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

Arrays in NumPy are printed as the word array followed by structure, similar to embedded Python lists. Let's create a similar list:

>>> l = [[[ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.]],

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

>>> l
[[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], 
 [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]]

The first level of this compound list l has exactly 2 elements, just as the first dimension of the array a (# of rows). Each of these elements is itself a list with 3 elements, which is equal to the second dimension of a (# of columns). Finally, the most nested lists have 4 elements each, same as the third dimension of a (depth/# of colors).

So you've got exactly the same structure (in terms of dimensions) as in Matlab, just printed in another way.

Some caveats:

  1. Matlab stores data column by column ("Fortran order"), while NumPy by default stores them row by row ("C order"). This doesn't affect indexing, but may affect performance. For example, in Matlab efficient loop will be over columns (e.g. for n = 1:10 a(:, n) end), while in NumPy it's preferable to iterate over rows (e.g. for n in range(10): a[n, :] -- note n in the first position, not the last).

  2. If you work with colored images in OpenCV, remember that:

    2.1. It stores images in BGR format and not RGB, like most Python libraries do.

    2.2. Most functions work on image coordinates (x, y), which are opposite to matrix coordinates (i, j).

Answer from ffriend on Stack Overflow
Top answer
1 of 6
71

You have a truncated array representation. Let's look at a full example:

>>> a = np.zeros((2, 3, 4))
>>> a
array([[[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.]],

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

Arrays in NumPy are printed as the word array followed by structure, similar to embedded Python lists. Let's create a similar list:

>>> l = [[[ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.]],

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

>>> l
[[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], 
 [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]]

The first level of this compound list l has exactly 2 elements, just as the first dimension of the array a (# of rows). Each of these elements is itself a list with 3 elements, which is equal to the second dimension of a (# of columns). Finally, the most nested lists have 4 elements each, same as the third dimension of a (depth/# of colors).

So you've got exactly the same structure (in terms of dimensions) as in Matlab, just printed in another way.

Some caveats:

  1. Matlab stores data column by column ("Fortran order"), while NumPy by default stores them row by row ("C order"). This doesn't affect indexing, but may affect performance. For example, in Matlab efficient loop will be over columns (e.g. for n = 1:10 a(:, n) end), while in NumPy it's preferable to iterate over rows (e.g. for n in range(10): a[n, :] -- note n in the first position, not the last).

  2. If you work with colored images in OpenCV, remember that:

    2.1. It stores images in BGR format and not RGB, like most Python libraries do.

    2.2. Most functions work on image coordinates (x, y), which are opposite to matrix coordinates (i, j).

2 of 6
27

No need to go in such deep technicalities, and get yourself blasted. Let me explain it in the most easiest way. We all have studied "Sets" during our school-age in Mathematics. Just consider 3D numpy array as the formation of "sets".

x = np.zeros((2,3,4)) 

Simply Means:

2 Sets, 3 Rows per Set, 4 Columns

Example:

Input

x = np.zeros((2,3,4))

Output

Set # 1 ---- [[[ 0.,  0.,  0.,  0.],  ---- Row 1
               [ 0.,  0.,  0.,  0.],  ---- Row 2
               [ 0.,  0.,  0.,  0.]], ---- Row 3 
    
Set # 2 ----  [[ 0.,  0.,  0.,  0.],  ---- Row 1
               [ 0.,  0.,  0.,  0.],  ---- Row 2
               [ 0.,  0.,  0.,  0.]]] ---- Row 3

Explanation: See? we have 2 Sets, 3 Rows per Set, and 4 Columns.

Note: Whenever you see a "Set of numbers" closed in double brackets from both ends. Consider it as a "set". And 3D and 3D+ arrays are always built on these "sets".

๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - In this article, Iโ€™ll share several practical ways to create and manipulate 3D arrays in Python, focusing primarily on NumPy which is the gold standard for multidimensional array operations.
Discussions

Best way to visualize a 3d numpy array?
You can use voxels https://matplotlib.org/stable/gallery/mplot3d/voxels_rgb.html However these are usually opaque so you'll have to do some filtering operation to isolate only those values you're interested in. You mention temperature; perhaps you're interested in a hot region around some feature so you could filter out voxels with lower temperature. If you can pull in another library like plotly then you can use true volume rendering https://plotly.com/python/3d-volume-plots/ More on reddit.com
๐ŸŒ r/learnpython
6
2
February 24, 2023
What is 3D array in python?
1D Array: a1 = [1,2,3] 2D Array: a2 = [[1,2,3],[4,5,6],[7,8,9]] 3D Array: a3 = [ [ [1,2,3],[4,5,6],[7,8,9] ], [ [1,2,3],[4,5,6],[7,8,9] ], [ [1,2,3],[4,5,6],[7,8,9] ], ] An nD array is just a list of lists of lists n-levels down. Another way to think about is: How many indices do you need to refer to one specific element of the array? That "how many" is your n or dimensionality of the array: a1[0] # 1 index a2[0][1] # 2 indices a3[0][1][2] # 3 indices More on reddit.com
๐ŸŒ r/learnpython
10
8
February 19, 2024
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ arrays.ndarray.html
The N-dimensional array (ndarray) โ€” NumPy v2.5 Manual
An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension. The type of items in the array is ...
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ numpy tutorial โ€บ numpy 3d array
NumPy 3D array | Learn the Examples of NumPy 3D array
April 15, 2023 - In NumPy, you can create a three-dimensional array by creating an object that represents x by y by z, where x represents the outermost list, y represents the lists nested inside x, and z represents the values inside each y-nested list.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Python Like You Mean It
pythonlikeyoumeanit.com โ€บ Module3_IntroducingNumpy โ€บ AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array โ€” Python Like You Mean It
Keeping track of the meaning of ... to NumPy, but allows users provide explicit labels for an arrayโ€™s dimensions; that is, you can name each dimension. Using an xarray to select Bradโ€™s scores could look like grades.sel(student='Brad'), for instance. This is a valuable library to look into at your leisure. Letโ€™s build up some intuition for arrays with a dimensionality higher than 2. The following code creates a 3-dimensional array: # a 3D array, shape-(2, ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @bouimouass.o โ€บ what-3d-arrays-look-like-some-ways-to-construct-them-and-their-applications-5f054ce9adb8
What 3D arrays look like, some ways to construct them and their applications? | by Omar | Medium
July 23, 2023 - It is a rectangular array with three dimensions: rows, columns, and slices. The rows are represented by the first index, the columns are represented by the second index, and the slices are represented by the third index.
๐ŸŒ
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 - import numpy as np import pandas as pd twoD = np.array([[1, 2, 3, 4], [10, 20 , 30, 40], [100, 200, 300, 400]]) twoD.shape # 3Rows X 4 Colums twoD.sum(axis=0) #array([1+10+100, 2+20+200, 3+ 30 + 300]) twoD.sum(axis=1) #array([1+2+3+4, 10+20+30+40, 100+200+300+400) twoD.sum() #np.int64(1110) => sums everything ... The above image has two perpendicular axes forming a plane โ€” our 2D array. When we think in 3D, this plane becomes a horizontal layer (a slice along the Z-axis), ready to be stacked with others to form a cube.
๐ŸŒ
Data Science Dojo
discuss.datasciencedojo.com โ€บ python
Initializing a 3D Numpy array with random values in Python - Python - Data Science Dojo Discussions
January 30, 2023 - In the realm of data science and computational tasks, 3D Numpy arrays are a vital tool for managing multi-dimensional data. This thread explores the different techniques of initializing these arrays with random values, along with example codes.
๐ŸŒ
Quora
quora.com โ€บ How-can-you-create-an-array-3D-in-Python
How to create an array 3D in Python - Quora
Answer: In Python, you can create a 3D array using lists or, preferably, NumPy arrays. NumPy is a powerful library for numerical operations, and it provides convenient functions for working with multi-dimensional arrays. Here's how you can create a 3D array using NumPy:
๐ŸŒ
GitHub
bic-berkeley.github.io โ€บ psych-214-fall-2016 โ€บ reshape_and_3d.html
Reshaping and three-dimensional arrays โ€” Functional MRI methods
NumPy uses the same algorithm for reshaping a three-dimensional array: >>> arr_1d_bigger = np.arange(24) >>> arr_1d_bigger array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]) >>> arr_1d_bigger.shape (24,) >>> arr_3d = arr_1d_bigger.reshape((2, 3, 4)) >>> arr_3d array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]], <BLANKLINE> [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]) Here NumPy is showing us the two slices over the first dimension: >>> arr_3d[0, :, :] array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> arr_3d[1, :, :] array([[1
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.
๐ŸŒ
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
๐ŸŒ
DataCamp
campus.datacamp.com โ€บ courses โ€บ introduction-to-numpy โ€บ understanding-numpy-arrays
3D array creation | Python
numpy is loaded as np, and the sudoku_game and sudoku_solution arrays are available. ... Create a 3D array called game_and_solution by stacking the two 2D arrays, sudoku_game and sudoku_solution, on top of one another; in the final array, sudoku_game should appear before sudoku_solution.
๐ŸŒ
Medium
hidayatullahhaider.medium.com โ€บ understanding-numpy-axis-for-2d-3d-arrays-94e017b83202
Understanding Numpy axis(for 2d & 3d arrays) | by Hidayat35 | Medium
July 24, 2021 - import numpy as np np_array_3d=np.array( [[[0,1,2],[3,4,5],[6,7,8]], [[0,1,2],[3,4,5],[6,7,8]], [[0,1,2],[3,4,5],[6,7,8]]]) a=np.sum(np_array_3d, axis = (0)) print(np_array_3d.shape) print(a.shape) print(a)
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_array_reshape.asp
NumPy Array Reshaping
Pass -1 as the value, and NumPy will calculate this number for you. Convert 1D array with 8 elements to 3D array with 2x2 elements:
๐ŸŒ
Physics Forums
physicsforums.com โ€บ more sciences and computing โ€บ programming and computer science
Why are new dimensions added to the left in numpy arrays? โ€ข Physics Forums
February 26, 2021 - Hello, I am clear on 1D and 2D Numpy arrays, how to create them and address them). 1D array: single list 2D array: list containing multiple lists as elements 3D array: list containing lists which contain lists as elements Array elements can be address using indices as a[], a[][], a[][][]...