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 - Learn how to work with 3D arrays in Python using NumPy. This comprehensive guide covers creation methods, indexing, slicing, and applications like image processing
๐ŸŒ
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)
๐ŸŒ
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.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ arrays.ndarray.html
The N-dimensional array (ndarray) โ€” NumPy v2.4 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), ...
๐ŸŒ
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 an arrayโ€™s various dimensions can quickly become unwieldy when working with real datasets. xarray is a Python library that provides functionality comparable 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, 2, 2) >>> d3_array = np.array([[[0, 1], ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_creating_arrays.asp
NumPy Creating Arrays
In this array the innermost dimension (5th dim) has 4 elements, the 4th dim has 1 element that is the vector, the 3rd dim has 1 element that is the matrix with the vector, the 2nd dim has 1 element that is 3D array and 1st dim has 1 element that is a 4D array. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com ยท HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Find elsewhere
๐ŸŒ
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:
๐ŸŒ
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
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 ...
๐ŸŒ
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]]])
๐ŸŒ
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.
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ reshaping-3d-numpy-arrays-to-2d-a-comprehensive-guide-for-data-scientists
Reshaping 3D Numpy Arrays to 2D: A Guide for Data Scientists | Saturn Cloud Blog
December 5, 2023 - A Numpy array is a grid of values, all of the same type, and is indexed by a tuple of non-negative integers. The dimensions are defined by its shape, a tuple of integers that give the size of the array along each dimension.
๐ŸŒ
Enthought
docs.enthought.com โ€บ mayavi โ€บ mayavi โ€บ mlab_3d_plotting_functions.html
3D Plotting functions for numpy arrays โ€” mayavi 4.8.3 documentation
The mlab plotting functions take numpy arrays as input, describing the x, y, and z coordinates of the data. They build full-blown visualizations: they create the data source, filters if necessary, and add the visualization modules. Their behavior, and thus the visualization created, can be fine-tuned through keyword arguments, similarly to pylab.
๐ŸŒ
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.
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ absolute_beginners.html
NumPy: the absolute basics for beginners โ€” NumPy v2.5.dev0 Manual
Using np.newaxis will increase the dimensions of your array by one dimension when used once. This means that a 1D array will become a 2D array, a 2D array will become a 3D array, and so on.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ numpy โ€บ numpy-reshape-2d-to-3d-array
Numpy Reshape 2D To 3D Array - GeeksforGeeks
July 23, 2025 - We reshaped it into a 3D array with the shape (3, 3, 1). The resulting 3D array has three 2D slices, each with a shape of (3, 3). The additional dimension (the third dimension) has a size of 1, indicating that each 2D slice has a depth of 1. ... import numpy as np # Create a 2D array array_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # Reshape the 2D array into a 3D array with shape (2, 2, 3) array_3d = array_2d.reshape((2, 2, 3)) print(&quot;Original 2D array:&quot;) print(array_2d) print(&quot;\nReshaped 3D array:&quot;) print(array_3d)
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-creating-3d-list
Python - Creating a 3D List - GeeksforGeeks
December 11, 2024 - Python ยท import numpy as np # Create a 3D array with dimensions 2x3x4, initialized to 0 a = np.zeros((2, 3, 4)) print(a) The np.zeros() function creates an array filled with 0 with the specified dimensions. NumPy is optimized for large scale computations and is faster compared to native Python lists.