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.]])
Answer from Stephen Simmons on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library. Arrays are used to store multiple values in one single variable: ... An array is a special variable, which can hold more than one value at a time.
Spaces
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
Practice
Practice coding problems on W3Schools. Write code, submit, and get instant feedback.
W3Schools app iOS & Android NEW
The W3Schools app turns coding fundamentals into a game. Bite-sized lessons, streaks and XP. Free on iOS and Android.
Python For Loops
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
🌐
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.
Discussions

python - How do I create an empty array and then append to it in NumPy? - Stack Overflow
I want to create an empty array and append items to it, one at a time. xs = [] for item in data: xs.append(item) Can I use this list-style notation with NumPy arrays? More on stackoverflow.com
🌐 stackoverflow.com
arrays - How do I get an empty list of any size in Python? - Stack Overflow
In the example above the array is initialized with zeros. However, this is uncommon in python, unless you actually need it for low-level stuff. In most cases, you are better-off using an empty list or empty numpy array, as other answers suggest. More on stackoverflow.com
🌐 stackoverflow.com
[Python] How to make empty array?
The geniuses at my uni decided to teach python instead of PHP, so now I'm stuck with it for my assignments. Anywho, how do you make an empty array in python? Everything I've searched up only tells you how to make them manually, hard coding all the items, not a single one tells you how to just mak... More on neowin.net
🌐 neowin.net
5
March 24, 2008
How can I create a truly empty numpy array which can be merged onto (by a recursive function)?
I can't say I fully followed your problem statement, but you can create an array with a total size of zero if any of the dimensions has size zero: a = np.empty((0, 3)) # Doesn't really matter if you use `empty`, `zeros` or `ones` here Zero-size arrays are the neutral element wrt. concatenation along their zero-size dimension (if that's what you mean by "merging"): b = np.random.uniform(size=(20, 3)) c = np.concatenate([a, b], 0) (c == b).all() # True More on reddit.com
🌐 r/learnpython
2
2
September 21, 2023
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
🌐
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
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.
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!

Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-13.php
NumPy: Create an empty and a full array - w3resource
Generate an empty array using np.empty_like based on another array’s shape and then fill it with a designated number.
🌐
CodeRivers
coderivers.org › blog › create-empty-array-python
Creating Empty Arrays in Python - CodeRivers
February 22, 2026 - They are flexible and can be resized easily. numpy arrays, on the other hand, are more optimized for numerical computations and require all elements to be of the same data type. The simplest way to create an empty array in Python is by using the list data type.
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › empty()
Python Numpy empty() - Create Empty Array | Vultr Docs
November 18, 2024 - The numpy.empty() function in Python is a part of the NumPy library, commonly used for generating arrays with uninitialized entries. This method proves useful primarily when you need to allocate an array quickly without immediately populating ...
🌐
Python Examples
pythonexamples.org › python-create-an-empty-array
Python - Create an Empty Array
To create an empty array in Python, import array module, call array() method of array module, and pass the type code for the required type of elements in the array as argument. The array() method returns an empty Python array of specified type.
🌐
CodeGenes
codegenes.net › blog › how-to-create-an-empty-array-in-python
Creating Empty Arrays in Python: A Comprehensive Guide — codegenes.net
In Python, an array is a container that can hold multiple items of the same or different data types. An empty array is simply an array that contains no elements at the time of its creation.
🌐
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).
🌐
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 ?
🌐
CodeSpeedy
codespeedy.com › home › declare an empty array in python
Declare an empty array in Python - CodeSpeedy
September 19, 2023 - It takes a number as input which defines the length of the empty array. The other attribute is dtype, which I have defined as an object. ... itertools is a Python built-in library. After importing the library, I have used the repeat() function that enables an iterator to do a single job a number of times. In this example, I have given 0 and 10 as arguments for the repeat() function because I want to repeat 0, 10 times. I have also typecasted the iterator.repeat() function as a list to return an empty array.
🌐
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 - To create an empty array with the same shape and data type (dtype) as an existing array, use np.empty_like().
🌐
Neowin
neowin.net › technical help & support › web design & development
[Python] How to make empty array? - Web Design & Development - Neowin
March 24, 2008 - The geniuses at my uni decided to teach python instead of PHP, so now I'm stuck with it for my assignments. Anywho, how do you make an empty array in python? Everything I've searched up only tells you how to make them manually, hard coding all the items, not a single one tells you how to just make an empty array of x items.
🌐
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 - You can create an empty list using an empty pair of square brackets [] or the type constructor list(), a built-in function that creates an empty list when no arguments are passed.
🌐
YouTube
youtube.com › watch
python create empty array and append - YouTube
Instantly Download or Run the code at https://codegive.com sure! here's a tutorial on how to create an empty array in python and then append elements to it:...
Published: March 29, 2024
🌐
w3resource
w3resource.com › numpy › array-creation › empty.php
NumPy: numpy.empty() function - w3resource
The dtype parameter in the np.empty() function can be used to specify the data type of the empty array. In the first example, an empty 2D array of size (2, 2) is created with the specified data type int.