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 Answer from Big_Combination9890 on reddit.com
🌐
AskPython
askpython.com › home › multidimensional arrays in python: a complete guide
Multidimensional Arrays in Python: A Complete Guide - AskPython
February 27, 2023 - In this article, the creation and implementation of multidimensional arrays (2D, 3D as well as 4D arrays) have been covered along with examples in Python Programming language. To understand and implement multi-dimensional arrays in Python, the NumPy package is used.
🌐
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.
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array — Python Like You Mean It
NumPy is able to see the repeated structure among the list-of-lists-of-numbers passed to np.array, and resolve the two dimensions of data, which we deem the ‘student’ dimension and the ‘exam’ dimension, respectively. ... Although NumPy does formally recognize the concept of dimensionality precisely in the way that it is discussed here, its documentation refers to an individual dimension of an array as an axis. Thus you will see “axes” (pronounced “aks-ēz”) used in place of “dimensions”; however, they mean the same thing. NumPy specifies the row-axis (students) of a 2D array as “axis-0” and the column-axis (exams) as axis-1.
Top answer
1 of 2
10

A one dimensional array is an array for which you have to give a single argument (called index) to access a specific value.

E.G. with the following one dimensional array

array = [0,1,2,9,6,5,8]

The array at index 1 has the value 1. The array at index 3 has value 9. If you want to update the 3rd value to 8 in the array, you should do

array[2] = 8

A two-dimensional array is simply an array of arrays. So, you have to give two arguments to access a single value.

two_dim_array = [[1,2,3],[4,5,6],[7,8,9]]

If you want to update the 'second' value, you have to do

two_dim_array[0][1] = 'something'

That is because two_dim_array[0] is a one-dimensional array, and you still have to specify an index to access a value.

From now on, you can keep going deeper with the same reasoning. As any further dimension is another level in the list. So a three dimensional array would be :

3d_array = 
[
    [
        [1,2,3,4],
        [5,6,7,8]
    ],
    [
        [9,10,11,12],
        [13,14,15,16]
    ]
]

Now to access a value you have to give .. 3 parameters. Because

3d_array[0] // is a two-dim array
3d_array[0][1] // is a one-dim array
3d_array[0][1][0] // is a value

I suggest you start doing simple exercices to get you familiar with this concept, as it is really 101 programming stuff. W3resource has great exercices to get you started.

2 of 2
1

To declare a two-dimensional array, you simply list two sets of empty brackets, like this:

int numbers[][];

Here, numbers is a two-dimensional array of type int. To put it another way, numbers is an array of int arrays.

Often, nested for loops are used to process the elements of a two-dimensional array, as in this example:

for (int x = 0; x < 10; x++) 
{
    for (int y = 0; y < 10; y++) 
    {
        numbers[x][y] = (int)(Math.random() * 100) + 1
    }
}

To declare an array with more than two dimensions, you just specify as many sets of empty brackets as you need. For example:

int[][][] threeD = new int[3][3][3];

Here, a three-dimensional array is created, with each dimension having three elements. You can think of this array as a cube. Each element requires three indexes to Access.

You can nest initializers as deep as necessary, too. For example:

int[][][] threeD = 
    {  { {1,   2,  3}, { 4,  5,  6}, { 7,  8,  9} },
       { {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
       { {19, 20, 21}, {22, 23, 24}, {25, 26, 27} } };
🌐
freeCodeCamp
freecodecamp.org › news › multi-dimensional-arrays-in-python
Multi-Dimensional Arrays in Python – Matrices Explained with Examples
December 11, 2025 - NumPy provides a powerful N-dimensional array object that you can use to create and manipulate multi-dimensional arrays efficiently. We'll now look at some examples of how to create and work with multi-dimensional arrays in Python using NumPy.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-reshape-2d-to-3d-array
Numpy Reshape 2D To 3D Array - GeeksforGeeks
July 23, 2025 - NumPy is a powerful library in Python used for numerical operations and data analysis. Reshaping arrays is a common operation in NumPy, and it allows you to change the dimensions of an array without changing its data. In this article, we'll discuss how to reshape a 2D NumPy array into a 3D array.
Find elsewhere
Top answer
1 of 3
54

You need to use np.transpose to rearrange dimensions. Now, n x m x 3 is to be converted to 3 x (n*m), so send the last axis to the front and shift right the order of the remaining axes (0,1). Finally , reshape to have 3 rows. Thus, the implementation would be -

img.transpose(2,0,1).reshape(3,-1)

Sample run -

In [16]: img
Out[16]: 
array([[[155,  33, 129],
        [161, 218,   6]],

       [[215, 142, 235],
        [143, 249, 164]],

       [[221,  71, 229],
        [ 56,  91, 120]],

       [[236,   4, 177],
        [171, 105,  40]]])

In [17]: img.transpose(2,0,1).reshape(3,-1)
Out[17]: 
array([[155, 161, 215, 143, 221,  56, 236, 171],
       [ 33, 218, 142, 249,  71,  91,   4, 105],
       [129,   6, 235, 164, 229, 120, 177,  40]])
2 of 3
5

[ORIGINAL ANSWER]

Let's say we have an array img of size m x n x 3 to transform into an array new_img of size 3 x (m*n)

Initial Solution:

new_img = img.reshape((img.shape[0]*img.shape[1]), img.shape[2])
new_img = new_img.transpose()

[EDITED ANSWER]

Flaw: The reshape starts from the first dimension and reshapes the remainder, this solution has the potential to mix the values from the third dimension. Which in the case of images could be semantically incorrect.

Adapted Solution:

# Dimensions: [m, n, 3]
new_img = new_img.transpose()
# Dimensions: [3, n, m]
new_img = img.reshape(img.shape[0], (img.shape[1]*img.shape[2]))

Strict Solution:

# Dimensions: [m, n, 3]
new_img = new_img.transpose((2, 0, 1))
# Dimensions: [3, m, n]
new_img = img.reshape(img.shape[0], (img.shape[1]*img.shape[2]))

The strict is a better way forward to account for the order of dimensions, while the results from the Adapted and Strict will be identical in terms of the values (set(new_img[0,...])), however with the order shuffled.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-creating-3d-list
Python - Creating a 3D List - GeeksforGeeks
December 11, 2024 - The inner loop appends rows to this 2D list. For numerical computations, using NumPy is more efficient and convenient. ... 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.
🌐
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) the output will be: (3, 3, 3) (3, 3) [[ 0 3 6] [ 9 12 15] [18 21 24]] here we have collapsed the 0 dimensions to apply the operations(in here it is sum) and the remaining y,z, and will catch the collapsed summed value.in simple words, the parameters of the axis (e.g: axis=0,1…..) indicated the dimension to collapse.
🌐
GeeksforGeeks
geeksforgeeks.org › python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
Given a 3D list, the task is to convert it into a 2D list. These type of problems are encountered while working on projects or w ... Python's NumPy package makes slicing multi-dimensional arrays a valuable tool for data manipulation and analysis.
Published   June 20, 2024
🌐
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), and via the methods and attributes of the ndarray.
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - In this article, I’ll share several ... everything from basic creation methods to advanced slicing techniques. ... A 3D array is essentially a collection of 2D arrays stacked on top of each other....
🌐
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 ...
🌐
DataCamp
campus.datacamp.com › courses › intro-to-python-for-data-science › chapter-4-numpy
2D NumPy Arrays | Python
If you ask for the type of these arrays, Python tells you that they are numpy.ndarray. numpy dot tells you it's a type that was defined in the numpy package. ndarray stands for n-dimensional array. The arrays np_height and np_weight are one-dimensional arrays, but it's perfectly possible to create 2 dimensional, three dimensional, heck even seven dimensional arrays! Let's stick to 2 in this video though. You can create a 2D ...
🌐
Medium
medium.com › @girginlerheryerde › layer-by-layer-understanding-3d-arrays-in-python-a5709b7ef8d1
Layer by Layer: Understanding 3D Arrays in Python | by Ayşenas Girgin | Medium
March 17, 2025 - Neural networks: Inputs are often ... a 3D array helps you manage it logically and cleanly. In Python, a 3D array is usually just a list of lists of lists....
🌐
Medium
panjeh.medium.com › convert-numpy-3d-array-to-2d-array-in-python-931a4cdf8b12
Convert numpy 3d array to 2d array in python | by Panjeh | Medium
April 24, 2024 - Convert numpy 3d array to 2d array in python Or convert 2d array to 1d array Attention: All the below arrays are numpy arrays. Imagine we have a 3d array (A) with this shape: A.shape = (a,b,c) Now we …
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-python › lessons › exploring-the-dimensions-a-beginners-guide-to-multidimensional-arrays-in-python
A Beginner's Guide to Multidimensional Arrays in Python
In this example, array is a 2-dimensional array, just like a 3-storey 'apartment building,' where every floor is an inner list. ... All indices in Python arrays are 0-based. Let's say you want to visit an apartment on the second floor (index 1) and bring a package to the first unit (index 0) ...