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
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-array-shape
NumPy Array Shape - GeeksforGeeks
July 15, 2025 - The shape of an array can be defined as the number of elements in each dimension. Dimension is the number of indices or subscripts, that we require in order to specify an individual element of an array.
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".

🌐
W3Schools
w3schools.com › python › numpy › numpy_array_reshape.asp
NumPy Array Reshaping
The shape of an array is the number of elements in each dimension. By reshaping we can add or remove dimensions or change number of elements in each dimension. Convert the following 1-D array with 12 elements into a 2-D array.
🌐
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 - Create a 3D array of the specified shape using random values and compute the cumulative sum along the third axis.
🌐
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], ...
🌐
OpenSourceOptions
opensourceoptions.com › numpy-array-shapes-and-reshaping-arrays
numpy: Array shapes and reshaping arrays – OpenSourceOptions
The dimensions of a 3D array are described by the number of layers the array contains, and the number of rows and columns in each layer. All layers must have the same number of rows and columns. numpy reports the shape of 3D arrays in the order layers, rows, columns.
🌐
Hyperskill
hyperskill.org › university › numpy › numpy-array-shape
NumPy Array Shape
September 4, 2024 - You can change the shape of a NumPy array using the .reshape() method, which takes a tuple representing the new shape. For example, to reshape a 2D array with 4 rows and 3 columns into a 3D array with dimensions 2x2x3, use .reshape((2, 2, 3)).
🌐
W3Schools
w3schools.com › python › numpy › numpy_array_shape.asp
NumPy Array Shape
The shape of an array is the number of elements in each dimension. NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements.
Find elsewhere
🌐
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
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - Using NumPy to work with 3D arrays ensures better performance and easier manipulation compared to plain Python lists ... import numpy as np # Temperature data for 5 US cities over 7 days across 3 metrics # (daily high, daily low, humidity) cities = ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"] days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] metrics = ["High Temp (°F)", "Low Temp (°F)", "Humidity (%)"] # Create a 3D array with random weather data weather_data = np.random.randint(50, 100, size=(len(cities), len(days), len(metrics))) # Access temperature for Chicago on Wednesday (high temp) chicago_wed_high = weather_data[2, 2, 0] print(f"Chicago's Wednesday high: {chicago_wed_high}°F")
🌐
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.
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .shape
Python:NumPy | ndarray | .shape | Codecademy
October 30, 2025 - import numpy as np · # 1D array · arr_1d = np.array([1, 2, 3, 4, 5]) print(arr_1d.shape) # 2D array · arr_2d = np.array([[1, 2, 3], [4, 5, 6]]) print(arr_2d.shape) # 3D array · arr_3d = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(arr_3d.shape) Copy to clipboard ·
🌐
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.
🌐
Nipraxis
textbook.nipraxis.org › reshape_and_3d.html
Reshaping and three-dimensional arrays — Practice and theory of brain imaging
... 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]]]) Remember from the three-dimensional arrays page page that we can read the shape of arr_3d - (2, 3, 4) - as “two rows, three columns, four planes”.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_array_shape.htm
NumPy - Array Shape
For a 2D array, the shape is a tuple with two elements: number of rows, number of columns. For a 3D array, the shape is a tuple with three elements: depth, number of rows, number of columns.
🌐
Real Python
realpython.com › numpy-reshape
Using NumPy reshape() to Change the Shape of an Array – Real Python
July 20, 2026 - You want to convert this 3D array into a 2D image with the same height as the original image and three times the width so that you’re displaying the image’s red, green, and blue components side by side. Now see what happens when you reshape the 3D array. You can extract the height and width of the image in pixels by unpacking image_array.shape and discarding the third dimension:
🌐
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
May 1, 2026 - In this example, -1 is used as a placeholder for the size of the first dimension, allowing Numpy to automatically calculate the appropriate size based on the total number of elements.. array_3d.shape[-1] means we are keeping the size of the last dimension the same.
🌐
Medium
medium.com › @amit25173 › understanding-numpy-shape-6fbb6b83891e
Understanding numpy.shape. If you think you need to spend $2,000… | by Amit Yadav | Medium
February 9, 2025 - For a 1D array, the shape might look like (n,), where n is the number of elements. For a 3D array, it could look like (x, y, z), representing depth, rows, and columns. Here’s another quick example to make it more fun.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-reshape-2d-to-3d-array
Numpy Reshape 2D To 3D Array - GeeksforGeeks
July 23, 2025 - The original 2D array is reshaped into a 3D array with a shape of (2, 2, 3). Reshaping arrays is a fundamental operation in NumPy, and it allows you to manipulate data in various ways.
🌐
Nipraxis
textbook.nipraxis.org › arrays_3d.html
Three-dimensional arrays — Practice and theory of brain imaging
The 3D array, as Numpy shows it, might not have an obvious resemblance to the image of the two planes shown above, but bear with us. ... The shape can be read as “two planes, each with 4 rows and 3 columns”, which corresponds to what is shown in the image of the planes above.