🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.append.html
numpy.append — NumPy v2.4 Manual
Delete elements from an array. ... Try it in your browser! >>> 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.
🌐
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.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.append.html
numpy.append — NumPy v2.5 Manual
Delete elements from an array. ... Try it in your browser! >>> import numpy as np >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.append.html
numpy.append — NumPy v2.3 Manual
Delete elements from an array. ... Try it in your browser! >>> import numpy as np >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])
🌐
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 ...
🌐
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])
🌐
Programiz
programiz.com › python-programming › numpy › methods › append
NumPy append() | Programiz
August 30, 2023 - The append() method adds the values at the end of a NumPy array.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.append.html
numpy.append — NumPy v2.1 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])
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.

🌐
Centron
centron.de › home › tutorials › numpy.append() in python - tutorial
numpy.append() in Python - Tutorial – centron
August 25, 2026 - The Python numpy.append() function allows for array concatenation and is especially useful when processing data efficiently. It returns a new array while keeping the original array unchanged.
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.append.html
numpy.append — NumPy v2.0 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.
🌐
DigitalOcean
digitalocean.com › community › tutorials › numpy-append-in-python
numpy.append() in Python | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
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.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-append-two-numpy-arrays
How to append two NumPy Arrays? - GeeksforGeeks
July 23, 2025 - A copy of array with values being appended at the end as per the mentioned object, along a given axis. ... import numpy array1 = numpy.array([1, 2, 3, 4, 5]) array2 = numpy.array([6, 7, 8, 9, 10]) # Appending both arrays using Append method array1 = numpy.append(array1, array2) print(array1)
🌐
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .append()
Python:NumPy | Built-in Functions | .append() | Codecademy
October 18, 2024 - The .append() function adds values to the end of an array and returns a ndarray with the values appended. ... Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
🌐
AskPython
askpython.com › python › array › append-an-array-in-python
How to append an Array in Python? - AskPython
June 30, 2020 - unicode: It represents the type of elements to be occupied by the array. For example, ‘d’ represents double/float elements. Further, the append() function operates in the same manner as that with Python Lists. ... The NumPy module can be used to create an array and manipulate the data against various mathematical functions.