You're forgetting to append the empty list beforehand. Thus why you get a, IndexError when you try to do arr[i].

arr = []
for i in range(10):
    arr.append([])
    for j in range(5):
        arr[i].append(i*j)
Answer from vallentin on Stack Overflow
๐ŸŒ
Python Forum
python-forum.io โ€บ thread-16863.html
2D arrays and appending values using a loop
Hi, I need some help with the appending of the values into the 2D array using a FOR loop. I am ok with printing the values, its the append that I need help with: Array=[[100,20],[90,29],[102,89],[2,2]] for row in Array: print ('Row Values:',...
Discussions

python - Append data in 2 dimensional array through for loop - Stack Overflow
I have a two dimensional array. I have created two nested loops to append data to this array, but I am getting error. The error is ''numpy.float64' object has no attribute 'append''. Any help to ov... More on stackoverflow.com
๐ŸŒ stackoverflow.com
July 16, 2020
Two dimensional array in python - Stack Overflow
But when I try to do, arr[1].append("bb1"), I get the following error: IndexError: list index out of range. Am I doing anything silly in trying to declare the 2-D array? Edit: but I do not know the number of elements in the array (both rows and columns). ... You do not "declare" arrays or anything else in python... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Numpy append 2D array in for loop over rows - Stack Overflow
I want to append a 2D array created within a for-loop vertically. I tried append method, but this won't stack vertically (I wan't to avoid reshaping the result later), and I tried the vstack() func... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Initialize 2D array within loop - Stack Overflow
Here np.append is sample code where I need to concatenate/append/hstack arrays together... (np.append didn't work.) How to populate 2D array within the loop? More on stackoverflow.com
๐ŸŒ stackoverflow.com
August 7, 2017
๐ŸŒ
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]] ?

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 62939358 โ€บ append-data-in-2-dimensional-array-through-for-loop
python - Append data in 2 dimensional array through for loop - Stack Overflow
July 16, 2020 - arr1[i][j] is selecting a single value, which you are then trying to append to, throwing the error. Try print(arr1[i][j]) to see this in action ยท G. Anderson โ€“ G. Anderson ยท 2020-07-16 16:39:18 +00:00 Commented Jul 16, 2020 at 16:39 ยท Use arr1[i][j] = x, if you want to assign to a position. ... @Austin, yes it workes but the values get added from 1st row. So 0th row is "NaN". Any suggestions for that ? ... The function call is not represented as a member function of numpy array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ appending-to-2d-list-in-python
Appending to 2D List in Python - GeeksforGeeks
July 23, 2025 - A 2D list in Python is a list of lists where each sublist can hold elements. Appending to a 2D list involves adding either a new sublist or elements to an existing sublist.
Find elsewhere
๐ŸŒ
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 - Pythonโ€™s built-in lists can represent 2D arrays as lists of lists. The simplest way to append values is using the append() method.
๐ŸŒ
Snakify
snakify.org โ€บ two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
To process 2-dimensional array, you typically use nested loops. The first loop iterates through the row number, the second loop runs through the elements inside of a row.
๐ŸŒ
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.
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ two-dimensional-array-in-python
Two Dimensional Array in Python - AskPython
December 27, 2019 - size = int(input()) array_input ... ... Elements in a 2D array can be inserted using the insert() function specifying the index/position of the element to be inserted....
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ 2d-python
Python - 2D List Examples - Dot Net Perls
Step 2 We access each sub-list and call append on it. This appends to the inner lists. Step 3 We display the element at indexes 0, 0 and this value is 1. With the print() method we can display the entire list contents. Step 4 This loop can iterate rows and columns in the 2D list.
๐ŸŒ
w3resource
w3resource.com โ€บ numpy โ€บ manipulation โ€บ append.php
Numpy: numpy.append() function - w3resource
April 25, 2026 - In the above code, the np.append() function is used to append arrays in NumPy. The first argument passed to the function is a one-dimensional NumPy array and the second argument is a two-dimensional NumPy array.
๐ŸŒ
DataCamp
datacamp.com โ€บ doc โ€บ numpy โ€บ append
NumPy append()
The `append()` function is typically used when you want to add more data to an array without altering the original array.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: append() to add values to an array | note.nkmk.me
February 4, 2024 - By default, when the first argument is a two-dimensional array, it is flattened to one dimension, and then the values from the second argument are appended to it. a_2d = np.arange(6).reshape(2, 3) print(a_2d) # [[0 1 2] # [3 4 5]] ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ preserving 2d list in for loops
r/learnpython on Reddit: preserving 2d list in for loops
April 25, 2023 -

Very early into my newest hobby, learning to code so forgive my poor etiquette

Trying to figure out when iterating through a 2d list with a for loop

This structure doesn't preserve the 2d list

new_list = []
for temp_var1 in two_d_lst:
    for temp_var2 in temp_var1:
        new_list.append(temp_var2.method())

But this structure does

new_list = []
for temp_var1 in two_d_lst:
    unpacking_lst = []
    for temp_var2 in temp_var1:
        unpacking_lst.append(temp_var2.method())
    new_list.append(unpacking_lst)

I'm not sure I understand why...

Greatly appreciate sarcastic remarks, especially if it helps me understand this.