October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

NumPy concatenate vs. append: Differences, defaults, and examples

NumPy concatenate joins arrays along an existing axis; append defaults to flattening and returns a new array. Learn which to use and how to join rows or columns safely.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

  • 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.