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.5.dev0 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.
Top answer
1 of 16
611

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
149

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!

Discussions

In Python, in what ways can you make an empty NumPy array?
In Python, in what ways can you make an empty NumPy array? More on transtutors.com
🌐 transtutors.com
2
January 30, 2023
python - Defining empty numpy array when we do not know the size - Stack Overflow
The same idea applies in numpy. While you can start with a (0,n) shaped array, and grow by concatenating (1,n) arrays, that is a lot slower than starting with a (m,n) array, and assigning values. There's a deleted answer that illustrates how to create an array by list append. More on stackoverflow.com
🌐 stackoverflow.com
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
Creating empty nxn square matrix of 0
It's a list comprehension that creates n distinct [0] * n lists, and it's a pretty common idiom. You can think of [[0] * n] * n as a = [0] * n b = [] for _ in range(n): b.append(a) # same `a` every time And the later as b = [] for _ in range (n): a = [0] * n b.append(a) # new `a` every time The i is irrelevant, and you'd commonly just use a name like _ communicating "this variable doesn't matter". More on reddit.com
🌐 r/learnpython
1
1
July 13, 2023
🌐
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).

🌐
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 arrays is a basic operation in NumPy. Two commonly used types are: Empty array: This array isn’t initialized with any specific values. It’s like a blank page, ready to be filled with data later.
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
The array object in NumPy is called ndarray. We can create a NumPy ndarray object by using the array() function.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Create an empty array (np.empty, np.empty_like)
January 22, 2024 - This article explains how to create an empty array (ndarray) in NumPy. There are two methods available: np.empty(), which allows specifying any shape and data type (dtype), and np.empty_like(), which ...
Find elsewhere
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › numpy empty array with examples
NumPy Empty Array With Examples - Spark By {Examples}
March 27, 2024 - NumPy empty() array function in Python is used to create a new array of given shapes and types, without initializing entries. This function takes three
🌐
Spark Code Hub
sparkcodehub.com › numpy › basics › empty-array-initialization
Mastering NumPy empty(): High-Performance Array Initialization
np.empty() function is designed to create arrays quickly by allocating memory without initializing the elements, making it one of NumPy’s fastest array creation methods.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
One of the most simplest method to initialize the array is by *Operator. In this example, we are creating different types of empty using an asterisk (*) operator.
Published   July 12, 2025
🌐
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
🌐
NumPy
numpy.org › doc › 2.4 › reference › routines.array-creation.html
Array creation routines — NumPy v2.4 Manual
empty(shape[, dtype, order, device, like]) · Return a new array of given shape and type, without initializing entries
🌐
Codegive
codegive.com › blog › numpy_make_empty_array.php
Numpy make empty array
numpy.empty(shape, dtype=float, order='C'): This is the most direct way to truly make an "empty" array. It allocates memory but does not initialize the array elements to any specific value. The values found in the array will be whatever happened to be in that memory location previously (often ...
🌐
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 - import numpy as np # Create empty array with object dtype arr = np.empty(5, dtype=object) print("Empty array using NumPy:") print(arr) # Create empty array with float dtype float_arr = np.empty(3, dtype=float) print("Empty float array:") ...
🌐
w3resource
w3resource.com › numpy › array-creation › empty.php
NumPy: numpy.empty() function - w3resource
1 month ago - In the second example, an empty 2D array of size (2, 2) is created with the specified data type float. The resulting array contains four undefined floating-point values. The values shown in the output are also machine-dependent and may vary each time the function is called. ... import numpy as np # Define a custom data type dt = np.dtype([('Employee Name:', np.str_, 16), ('Age:', np.int32), ('Salary:', np.float64)]) # Create an empty array with the custom data type employee = np.empty((2, 3), dtype=dt) # Print the array print(employee)
🌐
Quora
quora.com › How-do-you-create-an-empty-multidimensional-array-in-Python
How to create an empty multidimensional array in Python - Quora
Tuples are immutable in the sense that you can not change the elements it holds or add or remove elements. You can create an empty list calling list() or use []; you can create an empty tuple calling tuple().
🌐
OpenSourceOptions
opensourceoptions.com › 10-ways-to-initialize-a-numpy-array-how-to-create-numpy-arrays
10 Ways to Initialize a Numpy Array (How to create numpy arrays) – OpenSourceOptions
In truth, and empty array isn’t actually empty, it just contains very small, meaningless values. To create and empty numpy array, call the numpy.empty() function and pass it a shape tuple. The code below demonstrates how this is done.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy empty
NumPy Empty | Working and Examples of NumPy empty()
March 28, 2023 - In Python, the NumPy module is ... and the type and such creation of array are done by using a function known as an empty() function having the default data type as float and is required to set the values of the array manually ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai