You do not "declare" arrays or anything else in python. You simply assign to a (new) variable. If you want a multidimensional array, simply add a new array as an array element.

arr = []
arr.append([])
arr[0].append('aa1')
arr[0].append('aa2')

or

arr = []
arr.append(['aa1', 'aa2'])
Answer from ThiefMaster on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › appending-to-2d-list-in-python
Appending to 2D List in Python - GeeksforGeeks
July 23, 2025 - This modifies the contents of the sublist while keeping the 2D structure intact. += operator allows you to extend a sublist with multiple elements in a concise manner. ... This is equivalent to using extend(). If we want to append multiple sublists dynamically list comprehension is a concise option. ... List comprehension generates sublists dynamically and appends them to the original list.
Discussions

do you guys know how to add append an array in a 2d array?
my_list = [[1, 2, 3, 4, 5]] new_list = my_list * 5 print(new_list) Prints: [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] But be aware that this only creates multiple labels to the same [1, 2, 3, 4, 5] list object. Mutating any one of the inner lists mutates all of the inner lists as there is only one inner list object: new_list[0][0] += 40 print(new_list) print(my_list) # The original list object Prints: [[41, 2, 3, 4, 5], [41, 2, 3, 4, 5], [41, 2, 3, 4, 5], [41, 2, 3, 4, 5], [41, 2, 3, 4, 5]] [[41, 2, 3, 4, 5]] but you can reassign different objects within new_list: new_list[1] = [7,8,9] print(new_list) Prints: [[41, 2, 3, 4, 5], [7, 8, 9], [41, 2, 3, 4, 5], [41, 2, 3, 4, 5], [41, 2, 3, 4, 5]] If you actually want deep copies of the original inner list, you can use a list comprehension: my_list = [[1, 2, 3, 4, 5]] new_list = [my_list[0][:] for _ in range(5)] new_list[0][0] += 40 print(new_list) Prints: [[41, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] More on reddit.com
🌐 r/learnpython
5
5
February 19, 2024
python - How to define a two-dimensional array? - Stack Overflow
You can, however, create multidimensional sequences, as the answers here show. Remember that python variables are untyped, but values are strongly typed. SingleNegationElimination – SingleNegationElimination · 2011-07-12 16:05:19 +00:00 Commented Jul 12, 2011 at 16:05 ... I'm confused. Coming from other languages: it IS a difference between an 1D-Array containing 1D-Arrays and a 2D... More on stackoverflow.com
🌐 stackoverflow.com
Appending to 2D lists in Python - Stack Overflow
this is the most bizarre functionality ... in Python. seems almost like a bug. 2021-11-22T22:26:19.01Z+00:00 ... Save this answer. ... Show activity on this post. ... In other words, all three list references refer to the same list instance. ... Save this answer. ... Show activity on this post. Came here to see how to append an item to a 2D array, but the title ... More on stackoverflow.com
🌐 stackoverflow.com
How to convert 2D array into a dictionary
That's a 3d data structure, here I wrote this see if it does what you need. from pprint import pprint array = [[[0, 2], [1, 2], [2, 2]], [[0, 2], [1, 2], [2, 3]]] list = [] for i in array: keys = [k[0] for k in [j for j in i]] values = [k[1] for k in [j for j in i]] list.append({k:v for k, v in zip(keys, values)}) pprint(list) More on reddit.com
🌐 r/learnpython
3
3
November 8, 2020
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python tutorial: how-to guides for everyday python problems" › "how to append 2d array in python"
How to Append 2D Array in Python | Delft Stack
February 22, 2025 - Check out our article on transposing matrices in Python. array = [[1, 2], [3, 4]] array += [[5, 6]] print(array) ... This method is a shorthand for append() but modifies the list in place.
🌐
AskPython
askpython.com › python › two-dimensional-array-in-python
Two Dimensional Array in Python - AskPython
December 27, 2019 - ... size = int(input()) array_input ... print(array_input) ... Elements in a 2D array can be inserted using the insert() function specifying the index/position of the element to be inserted....
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
Another (but similar) way: create an empty list and then append a new element to it n times (this element should be a list of length m): ... But the easiest way is to use generator, creating a list of n elements, each of which is a list of m zeros: ... In this case each element is created independently from the others. The list [0] * m is n times consructed as the new one, and no copying of references occurs. Say, a program takes on input two-dimensional array in the form of n rows, each of which contains m numbers separated by spaces.
🌐
Reddit
reddit.com › r/learnpython › do you guys know how to add append an array in a 2d array?
r/learnpython on Reddit: do you guys know how to add append an array in a 2d array?
February 19, 2024 -

say i have array [[1,2,3,4,5]], how can i duplicate it 5 times to [[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5],[1,2,3,4,5]] ?

Find elsewhere
🌐
Dot Net Perls
dotnetperls.com › 2d-python
Python - 2D List Examples - Dot Net Perls
Programs often must model 2 dimensions, not just one. In a Python list we can place other lists: this creates a 2D representation of objects. We can access elements on each list with an index—we must specify the X and Y positions. To construct a 2D list, we can use append() or an initializer.
Top answer
1 of 7
1263

You're technically trying to index an uninitialized array. You have to first initialize the outer list with lists before adding items; Python calls this "list comprehension".

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5
Matrix = [[0 for x in range(w)] for y in range(h)] 

#You can now add items to the list:

Matrix[0][0] = 1
Matrix[6][0] = 3 # error! range... 
Matrix[0][6] = 3 # valid

Note that the matrix is "y" address major, in other words, the "y index" comes before the "x index".

print Matrix[0][0] # prints 1
x, y = 0, 6 
print Matrix[x][y] # prints 3; be careful with indexing! 

Although you can name them as you wish, I look at it this way to avoid some confusion that could arise with the indexing, if you use "x" for both the inner and outer lists, and want a non-square Matrix.

2 of 7
487

If you really want a matrix, you might be better off using numpy. Matrix operations in numpy most often use an array type with two dimensions. There are many ways to create a new array; one of the most useful is the zeros function, which takes a shape parameter and returns an array of the given shape, with the values initialized to zero:

>>> import numpy
>>> numpy.zeros((5, 5))
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.,  0.]])

Here are some other ways to create 2-d arrays and matrices (with output removed for compactness):

numpy.arange(25).reshape((5, 5))         # create a 1-d range and reshape
numpy.array(range(25)).reshape((5, 5))   # pass a Python range and reshape
numpy.array([5] * 25).reshape((5, 5))    # pass a Python list and reshape
numpy.empty((5, 5))                      # allocate, but don't initialize
numpy.ones((5, 5))                       # initialize with ones

numpy provides a matrix type as well, but it is no longer recommended for any use, and may be removed from numpy in the future.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
Python creates only one inner list and one 0 object, not separate copies. This shared reference behavior is known as shallow copying (aliasing). If we assign the 0th index to another integer say 1, then a new integer object is created with the value of 1 and then the 0th index now points to this new int object as shown below · Similarly, when we create a 2d array as "arr = [[0]*cols]*rows" we are essentially extending the above analogy.
Published: December 20, 2025
🌐
Python Guides
pythonguides.com › python-numpy-2d-array
Create A 2D NumPy Array In Python (5 Simple Methods)
May 9, 2025 - Cells, rows, columns and slices of a 2D sales array. import numpy as np matrix = [[1, 2], [3, 4]] matrix.append([5, 6]) # add a row to a nested list for row in matrix: row.append(0) # add a column print(matrix) arr = np.array([[1, 2], [3, 4]]) ...
🌐
CodeRivers
coderivers.org › blog › append-to-a-2d-array-python
Appending to a 2D Array in Python — CodeRivers
For example: ... Here, two_d_array is a 2D array with 3 rows and 3 columns. Each inner list represents a row, and the elements within the inner list are the columns of that row. The simplest way to append to a 2D array in Python is by using the built-in append method of lists.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to create a two dimensional array in python?
How To Create a Two Dimensional Array in Python? - Be on the Right Side of Change
June 11, 2022 - Now that you have a clear picture ... create/initialize an empty 2D array loaded with zeros, for every occurrence of a row, we fill all the column elements and append that to the row....
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-python › lessons › exploring-the-dimensions-a-beginners-guide-to-multidimensional-arrays-in-python
Exploring the Dimensions: A Beginner's Guide to Multidimensional Arrays in Python | CodeSignal Learn
append(Element): With append(), we can add a new floor and units on that floor to our 'apartment building'. ... Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignalStart learning today! We can visit every floor (outer array) and every apartment on each floor (inner array) by using nested loops. array = [["Apt 101", "Apt 102", "Apt 103"], ["Apt 201", "Exit Floor", "Apt 203"], ["Apt 301", "Apt 302", "Apt 303"]] # Loop through 2D array for floor in array: for unit in floor: print(unit, end =', ') print() """ Prints: Apt 101, Apt 102, Apt 103, Apt 201, Exit Floor, Apt 203, Apt 301, Apt 302, Apt 303, """
🌐
Guru99
guru99.com › home › python › python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
October 7, 2026 - Python 2D Array is an array placed inside another array, forming rows and columns like a table. The examples below show how to create, access, insert, update, delete, and size 2D arrays.
🌐
Scaler
scaler.com › home › topics › 2d array in python
2D Array in Python | Python Two-Dimensional Array - Scaler Topics
May 25, 2026 - Often, append is used instead when the value should go at the end rather than at a specific index. The insert method has the following syntax: Where arr1 is the array in which the element is inserted, ind is the index at which the element is inserted, and arr_insert is the array or element to be inserted. ... As we have seen in python, a 2D array is an array of arrays so that we can add an element in the inner array.
🌐
EyeHunts
tutorial.eyehunts.com › home › python 2d array append
Python 2D array append
June 27, 2023 - Here’s an example that demonstrates ... row in array_2d: print(row) ... We specify the index of the row (existing_row_index) and use the append() method to add elements directly to that row....
🌐
Medium
medium.com › @bharathurs42 › creating-a-2d-lists-python-1d3c1ad57235
Creating a 2D-list in Python. This is how easy it is to create a 2D… | by Bharath Urs | Medium
January 26, 2023 - arr2D = [[]] # isn't that simple - and then we start appending values into the array # or append new array objects into them · Now that the basic structure is in place, we start appending: We can append new subarrays (lists) or just values ...
🌐
DataCamp
datacamp.com › doc › numpy › append
NumPy append()
NumPy's `append()` function is used to add elements to the end of an existing array, effectively creating a new array with the additional elements.