If by "array" you actually mean a Python list, you can use

Use with AIa = [0] * 10

or

Use with AIa = [None] * 10
Answer from Sven Marnach on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
In this example, we are using Python List comprehension for 1D and 2D empty arrays. Using list comprehension like [[0] * 4 for i in range(3)] creates independent lists for each row.
Published: July 12, 2025
People also ask

How do I create an empty array in Python?
Use an empty list: items = []. For typed numbers use array("d") from the array module, and for math use NumPy's np.array([]).
๐ŸŒ
pythonguides.com
pythonguides.com โ€บ create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
How do I declare an empty array of size n in Python?
Python doesn't declare sizes, but [None] * n or [0] * n gives you n slots to fill by index. With NumPy, np.zeros(n) does the same.
๐ŸŒ
pythonguides.com
pythonguides.com โ€บ create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
Is a Python list the same as an array?
Not exactly. A list holds any mix of types and grows freely, while array.array and NumPy arrays hold one numeric type. For most code, a list is what people mean by an array in Python.
๐ŸŒ
pythonguides.com
pythonguides.com โ€บ create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
๐ŸŒ
Python Guides
pythonguides.com โ€บ create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
January 12, 2026 - Create an empty array in Python with [], declare one of size n, avoid the [[]] * n trap, use the array module or NumPy, and check if an array is empty.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-empty-list-tutorial-how-to-create-an-empty-list-in-python
Python Empty List Tutorial โ€“ How to Create an Empty List in Python
June 18, 2020 - If you want to learn how to create an empty list in Python efficiently, then this article is for you. You will learn: How to create an empty list using square brackets []. How to create an empty list using list(). Their use cases. How efficient th...
Find elsewhere
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-empty-list-guide-to-using-empty-lists-in-python
Python Empty List | Guide to Using Empty Lists in Python
June 27, 2024 - So, whether youโ€™re a beginner ... embark on this journey! You can create an empty list in Python using either square brackets [] or the list() function....
๐ŸŒ
DataCamp
datacamp.com โ€บ home โ€บ tutorials โ€บ python โ€บ a comprehensive guide to python empty lists
A Comprehensive Guide to Python Empty Lists | DataCamp
February 2, 2024 - def find_strings_starting_with_a(strings): # Initialize an empty list to store strings that start with 'A' strings_starting_with_a = [] # Iterate over the input list and append strings that start with 'A' to `strings_starting_with_a` for string in strings: if string.startswith('A'): strings_starting_with_a.append(string) return strings_starting_with_a # Example usage result = find_strings_starting_with_a(['Assert', 'Import', 'Function', 'Array', 'Arguments']) # 'result' will contain ['Assert', 'Array', 'Arguments'] ... In summary, mastering empty lists and their operations is crucial in Python programming, allowing for versatile data manipulation.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-initialize-an-empty-array-of-given-length-using-python
How to Initialize an Empty Array of given Length using Python
March 27, 2026 - Empty array using range() and append(): [None, None, None, None, None] Length: 5 ยท List comprehension provides a concise way to create empty arrays ?
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-check-if-list-empty-not
Check if a list is empty or not in Python - GeeksforGeeks
October 24, 2024 - Explanation: len(a) returns 0 for an empty list. Lists can be directly evaluated in conditions. Python considers an empty list as False.
Top answer
1 of 16
612

That is the wrong mental model for using NumPy efficiently. NumPy arrays are stored in contiguous blocks of memory. To append rows or columns to an existing array, the entire array needs to be copied to a new block of memory, creating gaps for the new elements to be stored. This is very inefficient if done repeatedly.

Instead of appending rows, allocate a suitably sized array, and then assign to it row-by-row:

>>> import numpy as np

>>> a = np.zeros(shape=(3, 2))
>>> a
array([[ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.]])

>>> a[0] = [1, 2]
>>> a[1] = [3, 4]
>>> a[2] = [5, 6]

>>> a
array([[ 1.,  2.],
       [ 3.,  4.],
       [ 5.,  6.]])
2 of 16
150

A NumPy array is a very different data structure from a list and is designed to be used in different ways. Your use of hstack is potentially very inefficient... every time you call it, all the data in the existing array is copied into a new one. (The append function will have the same issue.) If you want to build up your matrix one column at a time, you might be best off to keep it in a list until it is finished, and only then convert it into an array.

e.g.


mylist = []
for item in data:
    mylist.append(item)
mat = numpy.array(mylist)

item can be a list, an array or any iterable, as long as each item has the same number of elements.
In this particular case (data is some iterable holding the matrix columns) you can simply use


mat = numpy.array(data)

(Also note that using list as a variable name is probably not good practice since it masks the built-in type by that name, which can lead to bugs.)

EDIT:

If for some reason you really do want to create an empty array, you can just use numpy.array([]), but this is rarely useful!

๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-empty-array-in-Python
How to create an empty array in Python - Quora
Answer (1 of 6): The closest thing to an array in Python is a list, which is dynamic (the size can change). This is somewhat similar to a C++ [code ]std::vector[/code] or a Java [code ]ArrayList[/code] (if youโ€™re familiar with those languages and data structures). To make an empty list, you ...
Top answer
1 of 16
1381

You cannot assign to a list like xs[i] = value, unless the list already is initialized with at least i+1 elements (because the first index is 0). Instead, use xs.append(value) to add elements to the end of the list. (Though you could use the assignment notation if you were using a dictionary instead of a list.)

Creating an empty list:

>>> xs = [None] * 10
>>> xs
[None, None, None, None, None, None, None, None, None, None]

Assigning a value to an existing element of the above list:

>>> xs[1] = 5
>>> xs
[None, 5, None, None, None, None, None, None, None, None]

Keep in mind that something like xs[15] = 5 would still fail, as our list has only 10 elements.

range(x) creates a list from [0, 1, 2, ... x-1]

# 2.X only. Use list(range(10)) in 3.X.
>>> xs = range(10)
>>> xs
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Using a function to create a list:

>>> def display():
...     xs = []
...     for i in range(9): # This is just to tell you how to create a list.
...         xs.append(i)
...     return xs
... 
>>> print display()
[0, 1, 2, 3, 4, 5, 6, 7, 8]

List comprehension (Using the squares because for range you don't need to do all this, you can just return range(0,9) ):

>>> def display():
...     return [x**2 for x in range(9)]
... 
>>> print display()
[0, 1, 4, 9, 16, 25, 36, 49, 64]
2 of 16
233

Try this instead:

lst = [None] * 10

The above will create a list of size 10, where each position is initialized to None. After that, you can add elements to it:

lst = [None] * 10
for i in range(10):
    lst[i] = i

Admittedly, that's not the Pythonic way to do things. Better do this:

lst = []
for i in range(10):
    lst.append(i)

Or even simpler, in Python 2.x you can do this to initialize a list with values from 0 to 9:

lst = range(10)

And in Python 3.x:

lst = list(range(10))
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ declare-an-empty-list-in-python
Declare an Empty List in Python - GeeksforGeeks
July 12, 2025 - We can create an empty list in Python by just placing the sequence inside the square brackets[]. To declare an empty list just assign a variable with square brackets.
๐ŸŒ
Codemia
codemia.io โ€บ home โ€บ knowledge hub โ€บ create an empty list with certain size in python
Create an empty list with certain size in Python | Codemia
January 8, 2025 - Forgetting that array.array and bytearray exist. For typed numeric data, they use a fraction of the memory that a Python list requires. Using np.empty() without overwriting every element.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ declare-an-empty-list-in-python
Declare an Empty List in Python - GeeksforGeeks
May 1, 2025 - Declaring an empty list in Python creates a list with no elements, ready to store data dynamically.
๐ŸŒ
Built In
builtin.com โ€บ articles โ€บ python-check-if-list-is-empty
Python Check if a List Is Empty: A Guide | Built In
There are a variety of methods that can be used to check if a list is empty in Python, including the Truth Value Testing method, the len() function and the == operator. Learn more.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-check-if-a-list-is-empty-in-python
Python isEmpty() equivalent โ€“ How to Check if a List is Empty in Python
April 19, 2023 - In the code above, we used an if statement and the not operator to check if the people_list was empty. You can use the len() function in Python to return the number of elements in a data structure.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: Create an empty array (np.empty, np.empty_like) | note.nkmk.me
January 22, 2024 - Python's built-in list can also be converted to ndarray. For example, you can add elements to an empty list first and then convert it to an ndarray upon completion. ... If the final number of elements is already known, it is better to create an array of the necessary size using np.empty() or np.empty_like() and then assign values.