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
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!

๐ŸŒ
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. ... # initializes all the 10 spaces with 0โ€™s a = [0] * 10 print("Intitialising ...
Published: July 12, 2025
Discussions

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
I am trying to run this code ยท from numpy import * x = empty((2, 2), int) x = append(x, array([1, 2]), axis=0) x = append(x, array([3, 5]), axis=0) print(x) ... Traceback (most recent call last): File "/home/samip/PycharmProjects/MyCode/test.py", line 3, in x = append(x, array([1, 2]), axis=0) File "<__array_function__ internals>", line 5, in append File "/usr/lib/python3... 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 create empty array in python
This should help you create an empty array in Python based on your needs. ... Views: 5,825Q.7. From the following Trial Balance of Sumit and Amit, you are required to prepare Trading and profit & Loss Account for the year ended on 31st March 2020 Balance Sheet as on that date (12 marks). More on askfilo.com
๐ŸŒ askfilo.com
1
December 31, 2025
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
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
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).
Find elsewhere
๐ŸŒ
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:") ...
๐ŸŒ
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.
๐ŸŒ
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.
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]
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
Filo
askfilo.com โ€บ cbse โ€บ smart solutions โ€บ how can create empty array in python
How can create empty array in python... | Filo
December 31, 2025 - In Python, you can create an empty array in several ways depending on what you mean by "array" and which module you want to use.