Appending to numpy arrays is very inefficient. This is because the interpreter needs to find and assign memory for the entire array at every single step. Depending on the application, there are much better strategies.

If you know the length in advance, it is best to pre-allocate the array using a function like np.ones, np.zeros, or np.empty.

desired_length = 500
results = np.empty(desired_length)
for i in range(desired_length):
    results[i] = i**2

If you don't know the length, it's probably more efficient to keep your results in a regular list and convert it to an array afterwards.

results = []
while condition:
    a = do_stuff()
    results.append(a)
results = np.array(results)

Here are some timings on my computer.

def pre_allocate():
    results = np.empty(5000)
    for i in range(5000):
        results[i] = i**2
    return results

def list_append():
    results = []
    for i in range(5000):
        results.append(i**2)
    return np.array(results)

def numpy_append():
    results = np.array([])
    for i in range(5000):
        np.append(results, i**2)
    return results

%timeit pre_allocate()
# 100 loops, best of 3: 2.42 ms per loop

%timeit list_append()
# 100 loops, best of 3: 2.5 ms per loop

%timeit numpy_append()
# 10 loops, best of 3: 48.4 ms per loop

So you can see that both pre-allocating and using a list then converting are much faster.

Answer from Roger Fan on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.append.html
numpy.append — NumPy v2.2 Manual
Delete elements from an array. ... >>> import numpy as np >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-append-python
numpy.append() in Python - GeeksforGeeks
April 14, 2025 - numpy.append() function is used to add new values at end of existing NumPy array. This is useful when we have to add more elements or rows in existing numpy array.
Discussions

python - Optimal way to append to numpy array - Stack Overflow
I have a numpy array and I can simply append an item to it using append, like this: numpy.append(myarray, 1) In this case I just appended the integer 1. But is this the quickest way to append to an More on stackoverflow.com
🌐 stackoverflow.com
python - Concatenate a NumPy array to another NumPy array - Stack Overflow
Then I found this question and answer: How to add a new row to an empty numpy array ... That's what I ended up having to use but it does seem rather a kludge. 2020-10-16T01:52:02.173Z+00:00 ... Sven said it all, just be very cautious because of automatic type adjustments when append is called. More on stackoverflow.com
🌐 stackoverflow.com
Issues with Optimization / Appending to a Numpy Array
If you can pre-estimate the final size of the array, allocate it with that size using numpy.empty and then fill it without using append. If you can't predict the final size, append to plain old lists and when you have all the data in one list, then create the numpy array. When you append to a numpy array you end up copying all of the data into a new array so it is expensive for large arrays. More on reddit.com
🌐 r/learnpython
11
2
October 31, 2021
Numpy Array Append
Just so you know: A numpy array is not made to be appended to like a list is. In the background of np.append an entire new array has to be created, so it's expensive (slow). It's much better to use lists if you need to append data. More on reddit.com
🌐 r/learnpython
5
1
February 14, 2019
🌐
DataCamp
datacamp.com › doc › numpy › append
NumPy append()
NumPy's `append()` function is used to add elements to the end of an existing array, effectively creating a new array with the additional elements.
Top answer
1 of 2
33

Appending to numpy arrays is very inefficient. This is because the interpreter needs to find and assign memory for the entire array at every single step. Depending on the application, there are much better strategies.

If you know the length in advance, it is best to pre-allocate the array using a function like np.ones, np.zeros, or np.empty.

desired_length = 500
results = np.empty(desired_length)
for i in range(desired_length):
    results[i] = i**2

If you don't know the length, it's probably more efficient to keep your results in a regular list and convert it to an array afterwards.

results = []
while condition:
    a = do_stuff()
    results.append(a)
results = np.array(results)

Here are some timings on my computer.

def pre_allocate():
    results = np.empty(5000)
    for i in range(5000):
        results[i] = i**2
    return results

def list_append():
    results = []
    for i in range(5000):
        results.append(i**2)
    return np.array(results)

def numpy_append():
    results = np.array([])
    for i in range(5000):
        np.append(results, i**2)
    return results

%timeit pre_allocate()
# 100 loops, best of 3: 2.42 ms per loop

%timeit list_append()
# 100 loops, best of 3: 2.5 ms per loop

%timeit numpy_append()
# 10 loops, best of 3: 48.4 ms per loop

So you can see that both pre-allocating and using a list then converting are much faster.

2 of 2
2

If you know the size of the array at the end of the run, then it is going to be much faster to pre-allocate an array of the appropriate size and then set the values. If you do need to append on-the fly, it's probably better to try to not do this one element at a time, instead appending as few times as possible to avoid generating many copies over and over again. You might also want to do some profiling of the difference in timings of np.append, np.hstack, np.concatenate. etc.

🌐
Reddit
reddit.com › r/learnpython › issues with optimization / appending to a numpy array
r/learnpython on Reddit: Issues with Optimization / Appending to a Numpy Array
October 31, 2021 -

https://paste.ofcode.org/zpT6HK22LuswbXhTHZfUK6

I am working on a starter project which involves storing pixel coordinates for various "territories" (dictionaries) on a map. Because there are a huge amount of coordinates (33 million pixels), I have been trying to optimize the program so it uses less memory. I have been using numpy's int16 type and ndarray to save memory. The problem I am getting however, is with adding pixels to territories. Each territory (dictionary) has a "pixels" key with an array as a value, and to add pixels to that array I use the following method:

def addPixel(territory, pixel):
    pixels = getProperty(territory, "pixels")
    territory["pixels"] = numpy.append(pixels, pixel)

This method, however, appears to be very slow, and it would take a huge amount of time to iterate over millions of pixels. Does anyone know of a faster way the append items to ndarrays?

Top answer
1 of 2
2
If you can pre-estimate the final size of the array, allocate it with that size using numpy.empty and then fill it without using append. If you can't predict the final size, append to plain old lists and when you have all the data in one list, then create the numpy array. When you append to a numpy array you end up copying all of the data into a new array so it is expensive for large arrays.
2 of 2
2
Numpy arrays are poorly suited to appending because they’re fixed-length, and doing an append operation copies the entire array to a new array with one more spot, and then puts the new thing in that spot. If your main operation is appending then you’re likely better off with standard Python lists, or alternatively you can implement your own appending algorithm that does larger resizes (e.g. double each time) and separately keep track of how many elements have been put into each territory so that you only need to resize when you run out of space again. More generally, it’s not clear what you’re actually doing here. It sounds like you’re using a sparse array type approach where you only store individual position coordinates, but if you’re in charge of managing the whole map maybe you’re better off just having a single map array that keeps track of which territory ‘owns’ each pixel? Note that numpy is optimised for vectorised operations that apply to a large portion of an array at the same time. If you find yourself looping through a numpy array there’s probably something that could be handled better with vectorised operations, and if not it’s possible a numpy array is the wrong data structure to use :-)
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: append() to add values to an array | note.nkmk.me
February 4, 2024 - Modified: 2024-02-04 | Tags: Python, NumPy · In NumPy, the np.append() function allows you to add values (elements, rows, or columns) to either the end or the beginning of an array (ndarray). numpy.append — NumPy v1.26 Manual · Note that ...
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › append
Python Numpy append() - Add Elements to Array | Vultr Docs
April 10, 2025 - Here, python append to numpy array is done efficiently by appending elements to a list first, then converting it to a NumPy array in one step.
🌐
TutorialsPoint
tutorialspoint.com › home › numpy › numpy append
NumPy Append
March 5, 2015 - The Numpy Append() method adds values to the end of an input array, allocating a new array for the result rather than modifying the original in place.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.append.html
numpy.append — NumPy v2.5.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.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to append numpy arrays examples
How to Append NumPy Arrays Examples - Python
March 27, 2024 - numpy.append() is used to append two or multiple arrays at the end of the specified NumPy array. The NumPy append() function is a built-in function in the NumPy package of Python.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.insert.html
numpy.insert — NumPy v2.4 Manual
>>> import numpy as np >>> a = np.arange(6).reshape(3, 2) >>> a array([[0, 1], [2, 3], [4, 5]]) >>> np.insert(a, 1, 6) array([0, 6, 1, 2, 3, 4, 5]) >>> np.insert(a, 1, 6, axis=1) array([[0, 6, 1], [2, 6, 3], [4, 6, 5]])
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-append-two-numpy-arrays
How to append two NumPy Arrays? - GeeksforGeeks
July 23, 2025 - import numpy array1 = numpy.array([1, 2, 3, 4, 5]) array2 = numpy.array([6, 7, 8, 9, 10]) # Appending both Arrays using concatenate() method.
🌐
Centron
centron.de › startseite › numpy.append() in python – tutorial
numpy.append() in Python - Tutorial
February 7, 2025 - The numpy.append() function is a versatile way to concatenate arrays in Python. It offers options for flattening arrays and appending along specific axes.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › numpy tutorial › numpy array append
NumPy Array Append | Examples of NumPy Array Append
April 14, 2023 - The basic syntax of the Numpy array append function is: numpy.append(ar, values, axis=None) numpy denotes the numerical python package. append is the keyword which denoted the append function. ar denotes the existing array which we wanted to ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
w3resource
w3resource.com › numpy › manipulation › append.php
Numpy: numpy.append() function - w3resource
May 29, 2024 - Create a new array by appending an element to an existing array. Generate a sequence of numbers with a specific pattern by using numpy.append() in a loop.
🌐
Reddit
reddit.com › r/learnpython › numpy array append
r/learnpython on Reddit: Numpy Array Append
February 14, 2019 -

I'm trying to find out how to append a list to a Numpy array.

So I have a list of lists that I then convert into a Numpy array. I then want to append a list to that array.

So let's say I have

list = [[a,b,c],[b,c,d],[a,d,b]]

I first do:

list = np.array(list)

... (code that does calculations on that numpy array)

I then want to append:

list2 = [c,b,a]

to list.

I've tried np.index as well as np.append, however both of them give me the following output:

list = list = [[a,b,c],[b,c,d],[a,d,b,c,b,a]]

when I want:

list = [[a,b,c],[b,c,d],[a,d,b],[c,b,a]]

If this is too convoluted let me know, I can try explain it better.

I appreciate the help.

🌐
GeeksforGeeks
geeksforgeeks.org › python › appending-values-at-the-end-of-an-numpy-array
Appending values at the end of an NumPy array - GeeksforGeeks
July 15, 2025 - Let us see how to append values at the end of a NumPy array. Adding values at the end of the array is a necessary task especially when the data is not fixed and is prone to change. For this task, we can use numpy.append() and numpy.concatenate(). This function can help us to append a single value as well as multiple values at the end of the array.
🌐
PyPI
pypi.org › project › npy-append-array
npy-append-array · PyPI
Raises ValueError instead of TypeError since version 0.9.14 to be more consistent with Numpy. NpyAppendArray can be used in multithreaded environments. ... from npy_append_array import NpyAppendArray import numpy as np arr1 = np.array([[1,2],[3,4]]) arr2 = np.array([[1,2],[3,4],[5,6]]) filename = 'out.npy' with NpyAppendArray(filename, delete_if_exists=True) as npaa: npaa.append(arr1) npaa.append(arr2) npaa.append(arr2) data = np.load(filename, mmap_mode="r") print(data)
      » pip install npy-append-array
    
Published   Jun 26, 2025
Version   0.9.19