You can use fill method to init the array.

x = np.empty(shape=(800,800))
x.fill(1)
Answer from Wang Hui on Stack Overflow
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-numpy-2d-array
Create A 2D NumPy Array In Python (5 Simple Methods)
May 16, 2025 - This method is invaluable when working with linear algebra operations or when you need a specialized initialization pattern. ... Letโ€™s apply these methods to a real-world example. Imagine youโ€™re analyzing quarterly sales data for different regions in the US. import numpy as np # Create a 2D array for quarterly sales data (rows: quarters, columns: regions) sales_data = np.array([ [250000, 320000, 180000, 310000], # Q1 sales for 4 regions [270000, 300000, 195000, 340000], # Q2 sales [310000, 350000, 220000, 370000], # Q3 sales [390000, 420000, 290000, 450000] # Q4 sales ]) # Region names and
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ numpy โ€บ numpy_creating_arrays.asp
NumPy Creating Arrays
To create an ndarray, we can pass a list, tuple or any array-like object into the array() method, and it will be converted into an ndarray: ... A dimension in arrays is one level of array depth (nested arrays). nested array: are arrays that ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.4 Manual
NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...), respectively. Lists and tuples can define ndarray creation: a list of numbers will create a 1D array, a list of lists will create a 2D array, further nested lists will create higher-dimensional arrays.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ python โ€บ define a two-dimensional array in python
Define a two-dimensional array in Python | Sentry
We can create a 2D array by passing a tuple to the zeros function. The following code will create a 3-by-3 2D array with all values set to zero: ... Note that numpy.matrix is deprecated and should not be used for this operation.
๐ŸŒ
W3docs
w3docs.com โ€บ python
How to initialize a two-dimensional array in Python?
You can use the built-in list function to create a 2D array (also known as a list of lists) in Python. Here is an example of how to create a 2D array with 3 rows and 4 columns, filled with zeroes: # create a 2D array with 3 rows and 4 columns, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
The code below, compares two ways of initializing a 2D list in Python. Using list multiplication ([[0]*cols]*rows) creates multiple references to the same inner list, causing aliasing where changes affect all rows. Using a nested list comprehension creates a separate list for each row, avoiding aliasing and correctly forming a 2D array.
Published ย  December 20, 2025
Find elsewhere
๐ŸŒ
OpenGenus
iq.opengenus.org โ€บ 2d-array-in-numpy
2D Arrays in NumPy (Python)
October 28, 2022 - ... To get a specific element from an array use arr[r,c] here r specifies row number and c column number. ... To get all elements of Row or Column : is used to specify that we need to fetch every element. arr[1,:] #This will return all elements of 1st row in the form of array ...
๐ŸŒ
MLJAR
mljar.com โ€บ answers โ€บ define-two-dimensional-array-python
Define two-dimensional array in Python
w = 6 # width, number of columns h = 4 # height, number of rows array = [[0 for x in range(w)] for y in range(h)] ... REMEMBER Be careful with idexing, you can't go out of range! ... This way is much easier. You can use zeros function from numpy to create 2D array with all values set to zero:
๐ŸŒ
NumPy
numpy.org โ€บ devdocs โ€บ user โ€บ basics.creation.html
Array creation โ€” NumPy v2.5.dev0 Manual
NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...), respectively. Lists and tuples can define ndarray creation: a list of numbers will create a 1D array, a list of lists will create a 2D array, further nested lists will create higher-dimensional arrays.
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 160559 โ€บ empty-2d-array
python - Empty 2D Array [SOLVED] | DaniWeb
For heavy numeric work, prefer NumPy arrays for performance and vectorization; initialize once you know dimensions: arr = numpy.zeros((rows, cols)) (NumPy zeros). More on the aliasing gotcha: Python FAQ: multidimensional lists. defaultdict docs: collections.defaultdict. hoe to write a generic code for creating a empty 2D array and dynamically insert values in it.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ multidimensional arrays?
r/learnpython on Reddit: Multidimensional arrays?
September 15, 2023 -

Hello!

I have 5 sets, each set contains a number of elements of variable length (eg. set 1 has 100 elements, set 2 has 150 and so on)

Is it possible to store these sets in a single structure?

For example, if I want to print the 35th elements of the 3rd set, I could call it simply by saying something like MyContainer[setN][elementN]

I was trying to use a 2D array but I can't initialize its shape, since each set has a variable number of elements.

Can anybody point me to the right direction / best practice?

Thank you

๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-numpy-create-2d-array
Create 2D Array in NumPy
... Pass a list of lists to numpy.array() function. import numpy as np # create a 2D array with shape (3, 4) arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) print(arr) ... Pass shape of the required 2D array, as a tuple, as argument to numpy.zeros() function.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ how to initiate 2 d array in python
How to Initiate 2-D Array in Python | Delft Stack
February 2, 2024 - Besides the native Python array, NumPy should be the best option to create a 2-D array, or to be more precise, a matrix. You could create a matrix filled with zeros with numpy.zeros. >>> import numpy as np >>> column, row = 3, 5 >>> np.zeros(column, row) array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]]) Or initiate a matrix filled with ones with numpy.ones
๐ŸŒ
Quora
quora.com โ€บ What-is-the-syntax-for-declaring-a-2D-array-in-Python-using-a-list-comprehension
What is the syntax for declaring a 2D array in Python using a list comprehension? - Quora
Answer (1 of 3): [code]twoD_array = [[0 for i in range(num_columns)] for j in range(num_rows)] [/code]The above code makes a 2-dimensional array named twoD_array filled with zeros and size of num_rows x num_columns.
๐ŸŒ
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 - Once installed, you can import the Numpy module and use its functions and modules to work with multidimensional arrays. To create a 2D array loaded with zeros, you can simply use the numpy.zeros() method.