Use np.concatenate to join a sequence of arrays along an existing axis. Use np.append when adding values to one array is the clearest expression—but remember that it returns a new array, and its default axis=None flattens the inputs. For joining rows or columns, specify the axis explicitly.
What is the difference between np.concatenate and np.append?
| Function | Inputs | Default behavior | Result |
|---|---|---|---|
np.concatenate |
A sequence of arrays | axis=0: joins along the first existing axis |
A new array joining the inputs along an existing axis |
np.append |
One array and values to add | axis=None: flattens both inputs before joining |
A newly allocated copy; it does not modify the original array |
Both functions join array data, but their interfaces and defaults make them behave differently. NumPy describes concatenate as joining a sequence of arrays along an existing axis. Its inputs must have matching shapes except along the axis being joined. NumPy concatenate reference.
append takes a single array and values to add. Without an explicit axis, NumPy flattens both inputs, so a multidimensional input produces a one-dimensional result. With an axis specified, the arrays must have compatible dimensions and matching shapes everywhere except along that axis. NumPy append reference.
Why does np.append flatten my array?
Because axis defaults to None. For example, appending a two-dimensional array to another without setting axis flattens their elements into a one-dimensional result. This is often surprising when the intent was to add a row or column.
Recommended Free Tools
#1 Best Overall
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
flat = np.append(a, b) # axis=None: result is one-dimensional
rows = np.append(a, b, axis=0) # result shape is (3, 2)
For a predictable multidimensional join, specify the axis. The equivalent row join with concatenate makes the sequence of arrays explicit:
rows = np.concatenate((a, b), axis=0) # result shape is (3, 2)
How do I append rows or columns to a 2D NumPy array?
Choose the axis that represents the dimension you want to extend, and make the other dimensions match.
Rank #2
- Add rows: use
axis=0. Each input must have the same number of columns. - Add columns: use
axis=1. Each input must have the same number of rows.
For example, a has shape (2, 2) and b has shape (1, 2), so they can be joined as rows with axis=0. But b is not shaped for a column join; for axis=1, it would need one row for each row in a. A one-dimensional array such as np.array([5, 6]) is not a two-dimensional row for an axis-based append. Reshape it first, for example with np.array([[5, 6]]), when its contents and intended shape call for one row.
NumPy’s examples also show axis=None for flattening in concatenate; specify that explicitly if flattening is intended rather than relying on different defaults across functions. NumPy concatenate reference.
Does np.append modify the original array?
No. np.append returns a copy with the added values; it does not grow the original ndarray in place. Capture the returned array if you need the result:
a = np.array([1, 2])
result = np.append(a, 3)
# a is still [1, 2]; result is [1, 2, 3]
Joining arrays creates a result array as well. That matters when accumulating many chunks: repeatedly joining a growing result can require copying data into new results over and over. Keep chunks in a Python list and concatenate once when they are ready, or allocate the final destination once and fill its slices if you know the final shape. This is a practical consequence of the allocation behavior, not a universal timing benchmark.
chunks = [chunk_a, chunk_b, chunk_c]
result = np.concatenate(chunks, axis=0)
The NumPy 2.4.0 User Guide documents an out argument for concatenate and stack, allowing a correctly shaped output buffer to be supplied in supported versions. Check the documentation for the NumPy version installed in your environment before relying on version-specific options. NumPy 2.4.0 release notes.
Is np.concatenate faster than np.append?
There is no universal speed ranking established here. Both produce joined output, and append explicitly allocates and fills a new array. For repeated growth, the important issue is repeatedly rebuilding a larger result; batching chunks into one final concatenate or filling a preallocated destination can avoid that pattern. Actual timing depends on array sizes, dtype, memory layout, and workload. Benchmark the real operation if performance is critical rather than assuming one function is always faster.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
When should I use np.stack instead?
concatenate joins along an axis that already exists in the inputs. If the desired result should gain a new dimension, consider np.stack instead. For example, stacking two arrays shaped (2,) along a new axis can produce shape (2, 2), whereas concatenating them joins their existing one-dimensional axis. Confirm the output shape you need before choosing. NumPy stack reference.
Version and special-case notes
The current stable documentation identifies NumPy 2.5, and the concatenate reference notes that numpy.concat was added in NumPy 2.0 as a shorthand. The out-buffer detail above is specifically documented in the NumPy 2.4.0 User Guide; check versioned documentation for APIs available in a particular installation. NumPy concatenate reference · NumPy release notes.
If working with masked arrays and the input masks must be preserved, use np.ma.concatenate. The ordinary concatenate reference warns that it does not preserve input masks. NumPy concatenate reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




