The way to "start" the array that you want is:

arr = np.empty((0,3), int)

Which is an empty array but it has the proper dimensionality.

>>> arr
array([], shape=(0, 3), dtype=int64)

Then be sure to append along axis 0:

arr = np.append(arr, np.array([[1,2,3]]), axis=0)
arr = np.append(arr, np.array([[4,5,6]]), axis=0)

But, @jonrsharpe is right. In fact, if you're going to be appending in a loop, it would be much faster to append to a list as in your first example, then convert to a numpy array at the end, since you're really not using numpy as intended during the loop:

In [210]: %%timeit
   .....: l = []
   .....: for i in xrange(1000):
   .....:     l.append([3*i+1,3*i+2,3*i+3])
   .....: l = np.asarray(l)
   .....: 
1000 loops, best of 3: 1.18 ms per loop

In [211]: %%timeit
   .....: a = np.empty((0,3), int)
   .....: for i in xrange(1000):
   .....:     a = np.append(a, 3*i+np.array([[1,2,3]]), 0)
   .....: 
100 loops, best of 3: 18.5 ms per loop

In [214]: np.allclose(a, l)
Out[214]: True

The numpythonic way to do it depends on your application, but it would be more like:

In [220]: timeit n = np.arange(1,3001).reshape(1000,3)
100000 loops, best of 3: 5.93 µs per loop

In [221]: np.allclose(a, n)
Out[221]: True
Answer from askewchan 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 › 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 - Here we are creating an empty array and then appending it to the array. ... 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)
🌐
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 array:") # Displaying the empty array print(arr) # Appending two new arrays to the 'arr' array vertically along axis 0 arr = np.append(arr, np.array([[10, 20, 30]]), axis=0) arr = np.append(arr, np.array([[40, 50, 60]]), axis=0) # Printing a message indicating that two new arrays are added to the original array print("After adding two new arrays:") # Displaying the updated 'arr' array after adding two new arrays print(arr)
🌐
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 - Let’s walk through a simple example to demonstrate how to use np.append(): import numpy as np empty_array = np.array([]) # Create an empty array new_row = np.array([1, 2, 3]) # Create a new row updated_array = np.append(empty_array, new_row, ...
🌐
Pythoneo
pythoneo.com › how-to-append-to-empty-array-in-numpy
How to Append to an Empty Array in Numpy (with Examples) - Pythoneo: Python Programming, Seaborn & Plotly Tutorials
November 17, 2025 - The append() function takes two arguments: the first argument is the empty array, and the second argument is the value or values that you want to append to the array. See also How to solve AttributeError: module 'numpy' has no attribute 'random'
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.append.html
numpy.append — NumPy v2.6.dev0 Manual
A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled.
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.append.html
numpy.append — NumPy v2.5 Manual
A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled.
🌐
Appdividend
appdividend.com › appending-a-new-row-to-an-empty-array-in-numpy
How to Append a New Row to an Empty Array in Numpy
September 7, 2025 - The easiest and most straightforward way to append a new row to an empty numpy array is to use the “numpy.append()” method.
🌐
Codegive
codegive.com › blog › numpy_append_to_empty_array.php
Numpy append to empty array
To append rows, your "empty" array needs to have 0 rows but a defined number of columns. This tells NumPy the expected width of your data.
🌐
CodeSpeedy
codespeedy.com › home › add a new row to an empty numpy array in python
Add a new row to an empty numpy array in Python - CodeSpeedy
November 4, 2022 - By utilizing the numpy.append() function, Numpy gives the ability to append a row to an empty Numpy array.
🌐
IncludeHelp
includehelp.com › python › how-to-add-a-new-row-to-an-empty-numpy-array.aspx
How to add a new row to an empty NumPy array?
May 26, 2023 - The numpy.append() appends values to the end of an array and it can also be used to add a new row in an empty NumPy array.
🌐
Medium
medium.com › @whyamit101 › how-to-append-to-a-ndarray-4d73c600f5e5
How to Append to a ndarray. If you think you need to spend $2,000… | by why amit | Medium
February 9, 2025 - It can be a single value, a list, or even another array. axis (optional): This determines whether you append along a specific axis or flatten the data into one dimension. If you set axis=None (default), the function flattens the result. If you specify an axis (e.g., axis=0), the values will be appended along that dimension. Let’s See It in Action! ... import numpy as np # Original array arr = np.array([10, 20, 30]) # Appending a single value new_arr = np.append(arr, 40) print("After appending 40:", new_arr) # Appending multiple values new_arr = np.append(arr, [50, 60]) print("After appending [50, 60]:", new_arr)
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.3 › reference › generated › numpy.append.html
numpy.append — NumPy v2.3 Manual
>>> a = np.array([1, 2], dtype=int) >>> c = np.append(a, []) >>> c array([1., 2.]) >>> c.dtype float64 · Default dtype for empty ndarrays is float64 thus making the output of dtype float64 when appended with dtype int64
Top answer
1 of 2
2

Appending to numpy arrays is computationally expensive in the long run since numpy needs to allocate new array (memory) for the concatenated array, copy the items from the old array to the new array, then finally copy the to be appended array to the new array. I suggest you avoid using np.append. I see that you run into memory issues using list.append, however if you store each ls as numpy arrays you should be able to save some space:

arr = []
ls = np.array([1,2,3])
arr.append(ls)
ls = np.array([1,2,3])
arr.append(ls)
.
.
.

arr = np.array(arr)

However, you can achieve your desired using np.append if you initalize arr with your first array:

arr = np.array([1,2,3,7])
ls = [0,1,0,1]
arr = np.stack([arr, ls])

print(arr[0])
#[1,2,3,7]
print(arr[1])
#[0,1,0,1]

If you do know the upper bound N of items you want in the array, and that you have same sized arrays of length d, you can pre-initialize memory. For example if N=2 and d=3:

N = 2
d = 3

arr = np.empty((N,d))
arr[0] = [1,2,3]
arr[1] = [4,5,6]

print(arr[0])
#[[1, 2, 3],
# [4, 5, 6]]
2 of 2
0

With a small example like this, examining the whole array will be more instructive than arr[0].

In [1]: arr = np.array([])
   ...: ls = [1,2,3,7]
   ...: arr1 = np.append(arr,ls)
In [2]: arr1
Out[2]: array([1., 2., 3., 7.])

The np.append action is just:

In [3]: np.concatenate([arr, np.array(ls)])
Out[3]: array([1., 2., 3., 7.])

It's just an alternative way of calling concatenate. It make some sense when adding one value to an existing array, as in np.append(np.array([1,2,3]), 4). Otherwise it is more of a problem than a solution. It is not a list append clone.

np.array([]) is not a clone of [] either. But your use of that plus the arr=np.append(arr,ls) assignment, suggests you are trying to clone the common list append loop.

Many other SO stress that repeated use of np.append (or anything in the np.concatenate family) is inefficient. Each use requires a full copy. At least temporarily you'll have the original arr and the new one, which is a bit bigger.

You say that building a list of arrays, and doing one np.concatenate (or variant) at the end will push your memory limits. As best I can reason the repeated concatenates will do the same. However, I haven't tried to test this; I don't like to intentionally create a memory error.

Here's a way of doing what you initially tried to do with append:

In [4]: arr = np.array([None,None],dtype=object)
In [5]: arr[0] = [1,2,3,7]
In [6]: arr[1] = np.array([1,2,3,7])
In [7]: arr
Out[7]: array([list([1, 2, 3, 7]), array([1, 2, 3, 7])], dtype=object)
In [8]: arr[0]
Out[8]: [1, 2, 3, 7]

An object dtype array is much closer to a list in nature. It too stores references, rather than values. But it doesn't have any of the computational benefits of a numeric dtype array.

You also tried:

In [11]: arr = np.zeros((0,1))
In [12]: arr
Out[12]: array([], shape=(0, 1), dtype=float64)
In [13]: np.append(arr, [1,2,3,7])
Out[13]: array([1., 2., 3., 7.])

Same thing as the original, except the starting array is different. But np.append docs, if we take time to read them, tell us that it ravels the inputs - unless we provide an axis. np.ravel(arr) is just np.array([])!

But if we just throw in an axis value like 0, we get concatenate dimension errors:

In [19]: np.append(arr, [1,2,3,7],axis=0)
Traceback (most recent call last):
  File "<ipython-input-19-a30d55b63eca>", line 1, in <module>
    np.append(arr, [1,2,3,7],axis=0)
  File "<__array_function__ internals>", line 5, in append
  File "/usr/local/lib/python3.8/dist-packages/numpy/lib/function_base.py", line 4745, in append
    return concatenate((arr, values), axis=axis)
  File "<__array_function__ internals>", line 5, in concatenate
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)

This traceback shows how the append is translated into a concatenate.

If we want to add a 4 element array to a "empty" we have to start with the right shape:

In [21]: arr = np.zeros((0,4))
In [22]: np.vstack([arr,[1,2,3,7]])
Out[22]: array([[1., 2., 3., 7.]])

vstack is another concatenate front end, one that will turn the [1,2,3,7] into a np.array([[1,2,3,7]]), with shape (1,4). Now a (0,4) can be joined with a (1,4) to make a (1,4).

So not only is repeated concatenate slower, it requires that we get the initial array just right. Despite its superficial similarity to list append, np.append does not allow us to ignore array dimensions and what np.concatenate requires.

🌐
IncludeHelp
includehelp.com › python › concatenating-empty-array-in-numpy.aspx
Python - Concatenating empty array in NumPy
This is equivalent to concatenation along the first axis after 1-D arrays of shape (N,) have been reshaped to (1, N). ... # Import numpy import numpy as np # Creating a numpy array arr = np.array([[10,20,30,40,50],[100,200,300,400,500]]) # Display original array print("Original array:\n",arr,"\n") # Creating an empty array e_arr = np.array([], dtype=np.int64).reshape(0,5) # Concatenating empty array to numpy array res = np.vstack([arr, e_arr]) # Check that array is inserted if res.any(): print("-----------Array inserted-----------\n") # Display result print("Result:\n",res)