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
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.empty.html
numpy.empty — NumPy v2.6.dev0 Manual
For reproducible behavior, be sure to set each element of the array before reading. ... Try it in your browser! >>> import numpy as np >>> np.empty([2, 2]) array([[ -9.74499359e+001, 6.69583040e-309], [ 2.13182611e-314, 3.06959433e-309]]) #uninitialized · >>> np.empty([2, 2], dtype=np.int_) array([[-1073741821, -1067949133], [ 496041986, 19249760]]) #uninitialized
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!

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
🌐
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 - The NumPy version used in this article is as follows. Note that functionality may vary between versions. ... To create an empty array specifying shape and data type (dtype), use np.empty().
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › how-to-create-an-empty-and-a-full-numpy-array
How to create an empty and a full NumPy array - GeeksforGeeks
September 19, 2025 - Creating an empty array is useful when you need a placeholder for future data that will be populated later. It allocates space without initializing it, which can be efficient in terms of performance.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.empty.html
numpy.empty — NumPy v2.5 Manual
In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. ... Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None. ... Return an empty array with shape and type of input.
Find elsewhere
🌐
w3resource
w3resource.com › numpy › array-creation › empty.php
NumPy: numpy.empty() function - w3resource
The numpy.empty() function is used to create a new array of given shape and type, without initializing entries.
🌐
Educative
educative.io › answers › how-to-create-an-empty-numpy-array
How to create an empty NumPy array
numpy.zeros(shape, dtype=float, order='C') numpy.empty(shape, dtype=float, order='C') # Shape -> Shape of the new array, e.g., (2, 3) or 2. # dtype -> The desired data-type for the array,e.g., numpy.int8.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.empty.html
numpy.empty — NumPy v2.1 Manual
In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. ... Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None. ... Return an empty array with shape and type of input.
🌐
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.
Top answer
1 of 2
1

If by empty array, you mean an array with 0 dimensions, you can simply convert to a NumPy array an empty list:

import numpy as np

np.array([])
# array([], dtype=float64)

or use any of the NumPy's initialization functions with a (0,) or 0 shape, e.g.:

np.zeros((0,))
# array([], dtype=float64)

np.ones((0,))
# array([], dtype=float64)

np.empty((0,))
# array([], dtype=float64)

np.full((0,), 0.0)                                                                          
# array([], dtype=float64)

etc.


If by empty you mean an array of given size but not initialized (i.e. you only ask the OS for the required memory), you can use np.empty() specifying the size you need, e.g.:

np.empty((2, 3))
# array([[1.46643506e-316, 0.00000000e+000, 0.00000000e+000],
#        [0.00000000e+000, 0.00000000e+000, 0.00000000e+000]])
2 of 2
0

There are two ways an empty NumPy array can be created: numpy.zeros and numpy.empty.

The syntax for using numpy.zeros and numpy.empty is shown below:

numpy.zeros(shape, dtype=float, order='C')
numpy.empty(shape, dtype=float, order='C')

# Shape -> Shape of the new array, e.g., (2, 3) or 2.

# dtype -> The desired data-type for the array,e.g., numpy.int8. Default is numpy.float64. This parameter is optional.

# order -> Indicates whether multi-dimensional data should be stored in row-major (C-style) or column-major (Fortran-style) order in memory. This parameter is optional.

how to use numpy.zeros to create an empty NumPy array:

import numpy as np
myArr = np.zeros((2,3))
print(myArr)

how to use numpy.empty to create an empty NumPy array:

import numpy as np
myArr = np.empty((2,3))
print(myArr)

numpy.empty, unlike numpy.zeros, does not set the array values to zero and, ​therefore, may be marginally faster. On the other hand, it requires the user to manually set all the values in the array ​and should be used with caution.

🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_empty_function.htm
Numpy empty() Function
We can create an n-dimensional NumPy array by passing a tuple of two numeric values as an argument to the numpy.empty() function.
🌐
Programiz
programiz.com › python-programming › numpy › methods › empty
NumPy empty() | Programiz
August 30, 2023 - The empty() method creates a new array of given shape and type, without initializing entries. Example import numpy as np # create an array of uninitialized values array1 = np.empty(5) print(array1) # Output: [2.23196843e-316 0.00000000e+000 ...
🌐
Reddit
reddit.com › r/learnpython › how can i create a truly empty numpy array which can be merged onto (by a recursive function)?
r/learnpython on Reddit: How can I create a truly empty numpy array which can be merged onto (by a recursive function)?
September 21, 2023 -

I'm kind of stuck conceptually on how to make this happen. I have a recursive method that builds a binary tree, and stores the tree as an instance variable. However, the function is not allowed to return anything, so each recursive call should (according to me) modify in-place the tree instance variable. However, I'm not sure how to set up my instance variable such that all said and done it holds a multidimensional array that represents the tree.

Say I set initialize it as a 1x1 array with element zero as a placeholder. Then as I go about recursing through my tree I can merge to it... but at the end I'm left with a spare [0] element that I don't need. In this case, I'd need some kind of final stop condition and function to remove that unnecessary placeholder stump. I don't think this is possible?

Otherwise, say I initialize the instance variable as None. Then when the first series of recursive calls, it would have to reassign the tree variable to change from None to an ndarray object, but all future calls would have to merge to the array. I don't think this is what the function should be asked to do?

Is there a way to make a truly empty array that I can merge onto? (e.g. np.empty doesn't reallly give an empty array, it gives an array with placeholder values so I'm still left with a useless stump at the end).

🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.empty.html
numpy.empty — NumPy v2.2 Manual
In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. ... Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None. ... Return an empty array with shape and type of input.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.empty.html
numpy.empty — NumPy v2.3 Manual
In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. ... Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None. ... Return an empty array with shape and type of input.
🌐
Appdividend
appdividend.com › create-and-check-if-a-numpy-array-is-empty
How to Create and Check If a Numpy Array is Empty
July 10, 2025 - For a multidimensional empty array, the np.empty() function is more efficient. You can directly initialize an array with zero elements like this: import numpy as np empty_array = np.array([]) print(empty_array) print(empty_array.shape) ...
🌐
AskPython
askpython.com › python-modules › numpy › numpy-empty-and-empty_like
NumPy empty and empty_like - AskPython
October 4, 2026 - Pass the intended dimensions to np.empty, then assign every element before you inspect or calculate with the array. The slice assignment below initializes the complete allocation, so the printed values do not depend on whatever occupied that ...
🌐
YouTube
youtube.com › watch
How to Create an 'Empty Array' (Using np.empty()) | Python NumPy Tutorial for Beginners (2026) - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published: June 8, 2026
🌐
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.empty.html
numpy.empty — NumPy v1.25 Manual
On the other hand, it requires the user to manually set all the values in the array, and should be used with caution. ... >>> np.empty([2, 2]) array([[ -9.74499359e+001, 6.69583040e-309], [ 2.13182611e-314, 3.06959433e-309]]) #uninitialized