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.

Answer from hpaulj on Stack Overflow
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]
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!

Discussions

Python - How to create an empty numpy array and append to it, like lists - Stack Overflow
This is something I didn't find so easily on the internet. It's easy to create np.arrays, but how do you create an empty one so you can append on the go? More on stackoverflow.com
🌐 stackoverflow.com
python - How to add a new row to an empty numpy array - Stack Overflow
Next You’ll be prompted to create an account to view your personalized homepage. Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. Using standard Python arrays, I can do the following: Copyarr = [] arr.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
python - How to init an empty np array and add one-dimensional ones to it? - Stack Overflow
You need to start with an array ... rows or columns, otherwise np.append will flatten the result into a 1d array. Since you are starting with an empty array, you'll need to use a function that lets you specify the shape on creation.... More on stackoverflow.com
🌐 stackoverflow.com
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 › numpy › how-to-append-a-numpy-array-to-an-empty-array-in-python
How to append a NumPy array to an empty array in Python - GeeksforGeeks
July 23, 2025 - import numpy as np l = np.array([]) l = np.append(l, np.array(['G', 'F', 'G'])) l = np.append(l, np.array(['G', 'F', 'G'])) print(l) ... Here we are creating an empty array and then appending an empty row in it to see if there is any difference.
🌐
Python Guides
pythonguides.com › create-an-empty-array-in-python
Python Empty Array: Create, Declare, Size N and NumPy
January 12, 2026 - The variable is created the moment you assign the empty list to it. The list[int] part is a type hint. Your editor and tools like mypy use it, but Python doesn’t enforce it, which is why appending "ninety" still worked. So “declare an empty array” in Python really means one of two things: assign [], or create a list of a fixed size up front.
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python numpy howtos" › "how to append to empty array in numpy"
How to Append to Empty Array in NumPy | Delft Stack
February 2, 2024 - In this example, we have two new rows: [1, 2, 3] and [4, 5, 6]. To add all the rows from new_rows to the rows_list, we use the extend() method of the list. This operation efficiently appends all elements from new_rows to rows_list.
Find elsewhere
🌐
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 › python-exercises › numpy › python-numpy-exercise-119.php
Python NumPy: Add a new row to an empty numpy array - w3resource
August 29, 2025 - # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating an empty NumPy array with shape (0, 3) of integers arr = np.empty((0, 3), int) # Printing a message indicating an empty array will be displayed print("Empty ...
🌐
DataCamp
datacamp.com › home › tutorials › python › a comprehensive guide to python empty lists
A Comprehensive Guide to Python Empty Lists | DataCamp
February 2, 2024 - A drawback of .append() is that it only adds elements at the end of a list — this means that we have no control over where exactly to insert a new element when using .append(). The .insert() method, on the other hand, allows us to do exactly that. Here we pick up the example from the previous section and insert ’Truly’ between ’Python’ and ’Rocks!’. Note that Python uses zero-based indexing, which means that the index of the first element of the list is 0. Check out the example for more details: # Initialize an empty list my_list = [] # Append elements my_list.append('Python') my_list.append('Rocks!') my_list.append('It’s easy to learn!') # `my_list` is now ['Python', 'Rocks!', 'It’s easy to learn!'] # Showcase zero-based indexing in Python my_list[0] # Returns 'Python' my_list[1] # Returns 'Rocks' my_list[2] # Returns 'It's easy to learn!'
🌐
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.
🌐
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 ?
🌐
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).

🌐
CodeGenes
codegenes.net › blog › how-to-create-an-empty-array-in-python
Creating Empty Arrays in Python: A Comprehensive Guide — codegenes.net
In Python, arrays are an essential data structure used to store multiple values in a single variable. An empty array can serve as a starting point for building more complex data collections, allowing you to add elements as needed during the execution of your program.
🌐
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 specifying shape and data type (dtype), use np.empty().
Top answer
1 of 3
1

Collect the lists in a list, and do one array construction at the end:

In [687]: alist = []
     ...: alist.append([1,2])
     ...: alist.append([3,4])
     ...: arr = np.array(alist)    
In [688]: alist
Out[688]: [[1, 2], [3, 4]]    
In [689]: arr
Out[689]: 
array([[1, 2],
       [3, 4]])

Repeated np.append and np.concatenate is inefficient, and hard to get right.

Why are you surprised that you got a 1d array. Did you skip the np.append docs? Without axis that's what is does. With axis it just does np.concatenate. And as you found concatenate is picky about dimensions. You can join a (0,2) with a (1,2) on axis 0, but not a (1,0) with a (2,).

Imitating list methods with arrays doesn't work - unless you the read documentation carefully.

"empty array" is an ambiguous phrase. np.empty((1000,20,30)) makes a very large array of "arbitrary" values. np.array([]) makes a float dtype array with shape (0,). That has 0 elements, but so does an array with shape (10,0,1000). Lists are inherently 1d; arrays have both shape and dtype.

2 of 3
1

You need to start with an array with the right dimensions and append using the same dimensions. You also need to note whether you are appending rows or columns, otherwise np.append will flatten the result into a 1d array. Since you are starting with an empty array, you'll need to use a function that lets you specify the shape on creation. And then wrap the new rows in an outer list to make them 2d.

>>> arr=np.zeros((0,2), dtype=int)
>>> arr = np.append(arr, [[1,2]], axis=0)
>>> arr = np.append(arr, [[3,4]], axis=0)
>>> arr
array([[1, 2],
       [3, 4]])

As a side note, each append copies the array, which gets more and more expensive as the array grows. If you are using append to create a large array row by row, you should consider alternatives.

🌐
YouTube
youtube.com › watch
Python | Initializing an Empty NumPy Array - YouTube
This python tutorial teaches you how initialize an empty NumPy array, add elements to that array, and reshape the array. This is done with the NumPy module.
Published: December 31, 2023
🌐
W3Schools
w3schools.com › python › python_arrays.asp
Python Arrays
Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. ... Coding fundamentals as bite-sized lessons and challenges.
🌐
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 ...