Last Updated : 12 Jul, 2025
The numpy.concatenate() function combines multiple arrays into a single array along a specified axis. This function is particularly useful when working with large datasets or performing operations that require merging data from different sources. Unlike other array-joining functions like numpy.vstack() , numpy.hstack() which only join arrays vertically or horizontally numpy.concatenate() provides greater flexibility by allowing you to specify the axis along which the arrays are joined.
Syntax of numpy.concatenate()The syntax for the numpy.concatenate() function is as follows:
numpy.concatenate((array1, array2, ...), axis=0, out=None, dtype=None)
Parameters:
Let us now look at some practical examples to understand how numpy.concatenate() works
Example 1: Concatenating 1D ArraysSuppose you have two 1D arrays and want to combine them into a single array.
Python
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = np.concatenate((arr1, arr2))
print("Result:", result)
Output :
Example 2: Concatenating 2D Arrays Along Rows (axis=0)Result: [1 2 3 4 5 6]
For 2D arrays you can concatenate along rows (default behavior) or columns
Python
arr1 = np.array([[1, 2], [3, 4]])
arr2 = np.array([[5, 6]])
result = np.concatenate((arr1, arr2), axis=0)
print("Result:\n", result)
Output :
numpy_concatenate Comparison with Other FunctionsWhile numpy.concatenate() is versatile there are other functions in NumPy that perform similar tasks:
numpy.hstack():
For scenarios which require flexibility and efficiency numpy.concatenate() is the preferred choice.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4