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".

🌐
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. Arrays in NumPy are data structures with high performance suitable for mathematical operations. For example, the three levels of arrays nested inside one another represent the three-dimensional array in Python...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
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
Matrix multiplication of 3d arrays
I would have assumed that np.matmul would have been optimized for this. Why would you assume that? Any ideas why this is the case? Life is short and there were probably a million more important things to do and nobody volunteered code to optimize it. My assumption is that nothing is optimized unless you've actually read the code, or a discussion about the code, saying its optimized -- and even then I only half believe it. More on reddit.com
🌐 r/learnpython
11
10
November 5, 2024
How can I create a truly empty numpy array which can be merged onto (by a recursive function)?
I can't say I fully followed your problem statement, but you can create an array with a total size of zero if any of the dimensions has size zero: a = np.empty((0, 3)) # Doesn't really matter if you use `empty`, `zeros` or `ones` here Zero-size arrays are the neutral element wrt. concatenation along their zero-size dimension (if that's what you mean by "merging"): b = np.random.uniform(size=(20, 3)) c = np.concatenate([a, b], 0) (c == b).all() # True More on reddit.com
🌐 r/learnpython
2
2
September 21, 2023
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - Slicing 3D arrays follows the same pattern as other arrays, but with three dimensions: import numpy as np # Create a sample 3D array array_3d = np.arange(24).reshape(2, 3, 4) print("Original 3D array:") print(array_3d) # Get a specific 2D array (the first one) first_matrix = array_3d[0] ...
🌐
w3resource
w3resource.com › python-exercises › numpy › basic › numpy-basic-exercise-56.php
NumPy: Create a three-dimension array with shape (3,5,4) and set to a variable - w3resource
August 28, 2025 - ... # Importing the NumPy library ... = np.array([[[1, 5, 2, 1], [4, 3, 5, 6], [6, 3, 0, 6], [7, 3, 5, 0], [2, 3, 3, 5]], [[2, 2, 3, 1], [4, 0, 0, 5], [6, 3, 2, 1], [5, 1, 0, 0], [0, 1, 9, 1]], [[3, 1, 4, 2], [4, 1, 6, 0], [1, 2, 0, 6], [8, 3, 4, 0], [2, 0, 2, 8]]]) # Printing ...
🌐
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 - 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. For example, the following code creates a 3D NumPy array with 3 rows, 4 columns, and 2 slices:
🌐
Python Examples
pythonexamples.org › python-numpy-create-3d-array
Create 3D Array in NumPy
The function returns a numpy array with specified shape, and all elements in the array initialised to ones. import numpy as np # create a 3D array with shape (2, 3, 4) shape = (2, 3, 4) arr = np.ones(shape) print(arr)
🌐
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: height X width X channel · where channel can take 3 values representing R, G, B · from PIL import Image import numpy as np arr = np.random.randint(0, 256, (40, 40, 3), ...
Find elsewhere
🌐
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.
🌐
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)
🌐
Ipython-books
ipython-books.github.io › 13-introducing-the-multidimensional-array-in-numpy-for-fast-array-computations
IPython Cookbook - 1.3. Introducing the multidimensional array in NumPy for fast array computations
The following figure illustrates the structure of a 3D (3, 4, 2) array that contains 24 elements: The slicing syntax in Python translates nicely to array indexing in NumPy.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array — Python Like You Mean It
Using an xarray to select Brad’s ... for arrays with a dimensionality higher than 2. The following code creates a 3-dimensional array: # a 3D array, shape-(2, ......
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › 3d arrays in python
3d Arrays in Python | How to Create,Insert And Remove 3D Array In Python
April 23, 2024 - And the answer is we can go with the simple implementation of 3d arrays with the list. But for some complex structures, we have an easy way of doing it by including Numpy. It is not recommended which way to use it.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_reshape.asp
NumPy Array Reshaping
Meaning that you do not have to specify an exact number for one of the dimensions in the reshape method. Pass -1 as the value, and NumPy will calculate this number for you. Convert 1D array with 8 elements to 3D ...
🌐
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.
🌐
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 ... 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]]])...
🌐
NumPy
numpy.org › devdocs › user › quickstart.html
NumPy quickstart — NumPy v2.6.dev0 Manual
For example, the array for the coordinates of a point in 3D space, [1, 2, 1], has one axis. That axis has 3 elements in it, so we say it has a length of 3. In the example pictured below, the array has 2 axes.