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 - NumPy represents a three-dimensional array as an object with nested lists, 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
Discussions

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
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
How to create a 3D array in Python with Numpy? - Stack Overflow
I want to create a 2x2x3 three-dimensional array in Python. ... However, my output is a 2x3x2 array. ... What did I wrong? And can anyone please explain step by step how to build a 3D array, I am a bit confused about the rows, colums and axis. Thank you in advance. ... If you do numpy.zeros(... More on stackoverflow.com
🌐 stackoverflow.com
Initializing a 3D Numpy array with random values in Python - Python - Data Science Dojo Discussions
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. 1. Using the np.empty function: 2. Using the np.zeros ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
January 30, 2023
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - Iterating through 3D Python arrays in NumPy can be done using traditional nested loops or with efficient built-in tools like np.nditer.
🌐
Python Examples
pythonexamples.org › python-numpy-create-3d-array
Create 3D Array in NumPy
The function returns a numpy array with specified shape. import numpy as np # create a 3D array with shape (2, 3, 4) shape = (2, 3, 4) arr = np.empty(shape) print(arr)
🌐
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 - By assigning the array to a variable, the program enables easy access and manipulation of the three-dimensional data structure for various computational and analytical tasks. ... # Importing the NumPy library with an alias 'np' import numpy as np # Creating a NumPy array 'nums' containing a 3x5x4 multi-dimensional array nums = 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 a message indicating the array 'nums' print("Array:") print(nums)
🌐
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.
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.5 Manual
The type of items in the array is specified by a separate data-type object (dtype), one of which is associated with each ndarray. As with other container objects in Python, the contents of an ndarray can be accessed and modified by indexing or slicing the array (using, for example, N integers), and via the methods and attributes of the ndarray.
🌐
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, ...
🌐
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:
🌐
woteq
woteq.com › home › creating 3d numpy arrays in python: a comprehensive guide
Creating 3D NumPy Arrays in Python: A Comprehensive Guide - woteq Softwares
August 17, 2025 - The numpy.array() function is the most versatile way to create NumPy arrays. You can use it to create a 3D array from a nested Python list.
🌐
pythontutorials
pythontutorials.net › blog › numpy-3d-array
Mastering Numpy 3D Arrays: A Comprehensive Guide — pythontutorials.net
Mathematically, if we have a 3D array with shape (x, y, z), it means we have x number of 2D arrays, each of which has y rows and z columns. The shape attribute of a NumPy array is a tuple that gives the dimensions of the array.
🌐
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:
🌐
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 - N-dimensional arrays are just generalizations: each additional axis represents another independent parameter or dimension. We cannot visualize them directly beyond 3D. But mathematically, all indexing, slicing, and aggregation operations work the same way, just along additional axes. Numpy · Python ·
🌐
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
🌐
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.