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
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
Let's see different Pythonic ways ... initialize the array is by *Operator. In this example, we are creating different types of empty using an asterisk (*) operator....
Published: July 12, 2025
Discussions

python - How do I create an empty array and then append to it in NumPy? - Stack Overflow
For creating an empty NumPy array without defining its shape you can do the following: ... The first one is preferred because you know you will be using this as a NumPy array. NumPy converts this to np.ndarray type afterward, without extra [] 'dimension'. ... Note that in the background for python ... More on stackoverflow.com
🌐 stackoverflow.com
arrays - How do I get an empty list of any size in Python? - Stack Overflow
A variable is a name that is bound to a value, so that value must have something. 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 ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to create an empty array and append it? - Stack Overflow
The issue is that the line x = empty((2, 2), int) is creating a 2D array. 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
People also ask

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
How do I check if an array is empty?
For a list, if not items:. For a NumPy array, use arr.size == 0, because the truth value of an empty NumPy array raises ValueError.
🌐
pythonguides.com
pythonguides.com › create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
🌐
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 it with specific initial values.
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!

🌐
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.
Find elsewhere
🌐
Python Examples
pythonexamples.org › python-create-an-empty-array
Python - Create an Empty Array
To create an empty array, 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.
🌐
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 ?
🌐
CodeRivers
coderivers.org › blog › create-empty-array-python
Creating Empty Arrays in Python - CodeRivers
February 22, 2026 - The simplest way to create an empty array in Python is by using the list data type. You can create an empty list using the following syntax: ... In this example, we create an empty list named empty_list.
🌐
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.
🌐
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().
🌐
w3resource
w3resource.com › numpy › array-creation › empty.php
NumPy: numpy.empty() function - w3resource
The np.empty() function creates ... the function is called. In the first example, an empty 1D array of size 2 is created, resulting in an array with two undefined values....
🌐
CodeRivers
coderivers.org › blog › empty-array-in-python
Python's Empty Arrays: A Comprehensive Guide - CodeRivers
February 22, 2026 - NumPy arrays are more efficient for numerical computations compared to lists. They are homogeneous, meaning all elements in a NumPy array must have the same data type. To create an empty list (which can be considered an empty array), you can simply use empty square brackets:
🌐
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.
🌐
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.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-13.php
NumPy: Create an empty and a full array - w3resource
Sample Solution:- Python Code: # Importing the NumPy library with an alias 'np' import numpy as np # Creating an empty array of shape (3, 4) using np.empty() x = np.empty((3, 4)) # Printing the empty array 'x' print(x) # Creating a filled array ...
Top answer
1 of 4
3

I suspect you are trying to replicate this working list code:

In [56]: x = []                                                                 
In [57]: x.append([1,2])                                                        
In [58]: x                                                                      
Out[58]: [[1, 2]]
In [59]: np.array(x)                                                            
Out[59]: array([[1, 2]])

But with arrays:

In [53]: x = np.empty((2,2),int)                                                
In [54]: x                                                                      
Out[54]: 
array([[73096208, 10273248],
       [       2,       -1]])

Despite the name, the np.empty array is NOT a close of the empty list. It has 4 elements, the shape that you specified.

In [55]: np.append(x, np.array([1,2]), axis=0)                                  
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-55-64dd8e7900e3> in <module>
----> 1 np.append(x, np.array([1,2]), axis=0)

<__array_function__ internals> in append(*args, **kwargs)

/usr/local/lib/python3.6/dist-packages/numpy/lib/function_base.py in append(arr, values, axis)
   4691         values = ravel(values)
   4692         axis = arr.ndim-1
-> 4693     return concatenate((arr, values), axis=axis)
   4694 
   4695 

<__array_function__ internals> in concatenate(*args, **kwargs)

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)

Note that np.append has passed the task on to np.concatenate. With the axis parameter, that's all this append does. It is NOT a list append clone.

np.concatenate demands consistency in the dimensions of its inputs. One is (2,2), the other (2,). Mismatched dimensions.

np.append is a dangerous function, and not that useful even when used correctly. np.concatenate (and the various stack) functions are useful. But you need to pay attention to shapes. And don't use them iteratively. List append is more efficient for that.

When you got this error, did you look up the np.append, np.empty (and np.concatenate) functions? Read and understand the docs? In the long run SO questions aren't a substitute for reading the documentation.

2 of 4
2

You can create empty list by []. In order to add new item use append. For add other list use extend.

x = [1, 2, 3]
x.append(4)
x.extend([5, 6])

print(x) 
# [1, 2, 3, 4, 5, 6]
🌐
Python Help
pythonhelp.org › numpy › how-to-create-an-empty-numpy-array
Creating an Empty NumPy Array
This line imports the `numpy` library and assigns it a shorter alias `np`, which is commonly used in NumPy-related code. 2. **Create an Empty Array:** ```python empty_array = np.empty(0)
🌐
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