I think that's what you want

nodes = [[Node() for j in range(cols)] for i in range(rows)]

But it is not always a good practice to initialize lists. For matrices it may make sense.

If you're wondering: Documentation about list comprehensions

Demo code:

>>> class Node:
      def __repr__(self):
        return "Node: %s" % id(self)
>>> cols = 3
>>> rows = 4
>>> nodes = [[Node() for j in range(cols)] for i in range(rows)]
>>> from pprint import pprint
>>> pprint(nodes)
[[Node: 41596976, Node: 41597048, Node: 41596904],
 [Node: 41597120, Node: 41597192, Node: 41597336],
 [Node: 41597552, Node: 41597624, Node: 41597696],
 [Node: 41597768, Node: 41597840, Node: 41597912]]
Answer from JBernardo on Stack Overflow
🌐
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....
🌐
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
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
In real-world Often tasks have to store rectangular data table. [say more on this!] Such tables are called matrices or two-dimensional arrays. In Python any table can be represented as a list of lists (a list, where each element is in turn a list).
🌐
TutorialsPoint
tutorialspoint.com › python_data_structure › python_2darray.htm
Python - 2-D Array
Two dimensional array is an array within an array. It is an array of arrays. In this type of array the position of an data element is referred by two indices instead of one. So it represents a table with rows an dcolumns of data.
🌐
Scaler
scaler.com › home › topics › 2d array in python
2D Array in Python | Python Two-Dimensional Array - Scaler Topics
May 25, 2026 - It means that we can access any element of the array independently. In a 2D array, multiple arrays are inserted as elements in an outer array. Each element in a 2D array is represented by two indices, the row and the column. Unlike a one dimensional array, which uses a single index for individual ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
In method 1a, Python doesn't create 5 integer objects but creates only one integer object, and all the indices of the array arr point to the same int object as shown. 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: June 20, 2024
Find elsewhere
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 239490 › array-of-objects
python - Array of objects [SOLVED] | DaniWeb
@vegaseat's dictionary approach is ideal when many cells will be empty or coordinates are non-sequential; @twoshots's 2D-array idea is perfectly fine for a compact, fixed-size grid. A compact way to build a dense grid (using VPython objects) is a nested comprehension so you can index as grid[x][y] and change attributes directly:
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › 2d array in python
Comprehensive Guide to 2D Arrays in Python: Creation, Access, and Use
November 11, 2024 - When accessing elements in a 2D array, be cautious about boundary conditions to avoid Python 2d list indexing errors. Ensure that your code accounts for edge cases, such as the first and last rows and columns. ... # Check if a specific element is within bounds if 0 <= row < num_rows and 0 <= col < num_cols: value = array[row][col] else: print("Element is out of bounds.")
🌐
Cf
physics-python.astro.cf.ac.uk › Week6
PX1224 -Week6: Two Dimensional Arrays
As with all arrays in Python, mathematical operations can be performed on 2D arrays and matrices, but only if they are of correct shapes. (Shape is the python name for the dimensions of the array.) Attempting to combine (addition, subtraction etc) two arrays that are not compatable results in the error message ValueError: shape mismatch: objects cannot be broadcast to a single shape.
🌐
Processing
py.processing.org › tutorials › 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
Python.org
discuss.python.org › python help
2D NumPy array of objects vs. 2D Python list efficiency - Python Help - Discussions on Python.org
March 9, 2023 - I have a 2D list a of varying shape NumPy arrays and equivalent NumPy array of objects b = np.array(a, dtype='object'). It is inconvenient to slice a, e.g. a[:][1] is not equivalent to b[:, 1], can’t be expressed by slicing and requires a list comprehension [e[1] for e in a[:]] instead.
🌐
AskPython
askpython.com › python › array › multidimensional-arrays
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. It is a Python library that gives users access to a multidimensional array object, a variety of derived objects (such as masked arrays and matrices), and a selection of functions for quick operations on arrays and multi-dimensional matrices.
🌐
Sanshaacademy
sanshaacademy.com › python › ds › two_d_array.php
Two Dimensional (2D) Array in Python
# Creating a 2D array (list of lists) matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] # Accessing elements print(matrix[0][1]) # Output: 2 (row 0, column 1) # Modifying an element matrix[1][2] = 10 · for row in matrix: for element in row: print(element, end=" ") print() # Adding a new row matrix.append([10, 11, 12]) # Adding a new column to each row for row in matrix: row.append(0) import numpy as np # Creating a 2D array with NumPy arr = np.array([[1, 2], [3, 4]]) # Access and modify print(arr[1, 0]) # Output: 3 arr[0, 1] = 10
🌐
Python.org
discuss.python.org › python help › need help with a two-dimensional array
Need help with a two-dimensional array - Python Help - Discussions on Python.org
June 3, 2022 - Hello there! I’m an experienced coder who’s just getting into Python for the first time. I know several versions of BASIC, Pascal, C, C++, C#, PHP, MySQL… and so on. Here’s what I have: 1 2 3 4 5 6 7 8 A X X X X X X X X B X X X X X T X X C X X X X X X X X D X X X X X X X X E X X X X X X X X F X X X X X X X X G X X X X X X X X H X X X X X X X X This is a simple two-dimensional array.
🌐
Guru99
guru99.com › home › python › python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
October 7, 2026 - An array can only store similar types of elements. A Two Dimensional is defined as an Array inside the Array. The index of the array starts with 0 and ends with a size of array minus 1.
🌐
iO Flood
ioflood.com › blog › python-2d-array
Python 2D Array with Lists | Guide (With Examples)
February 10, 2024 - Numpy is a Python library used for numerical computations and has a built-in 2D array object that offers more functionalities than the native Python 2D array.
🌐
Sentry
sentry.io › sentry answers › python › define a two-dimensional array in python
Python Define a Two-Dimensional Array or Matrix | Sentry
September 23, 2026 - Create a 2D array in Python using numpy.zeros for matrix operations, or a nested list comprehension if you want to avoid the numpy dependency