How to Concatenate Arrays in Python (With Examples)


The easiest way to concatenate arrays in Python is to use the numpy.concatenate function, which uses the following syntax:

numpy.concatenate((a1, a2, ….), axis = 0)

where:

  • a1, a2 …: The sequence of arrays
  • axis: The axis along which the arrays will be joined. Default is 0.

This tutorial provides several examples of how to use this function in practice.

Example 1: Concatenate Two Arrays

The following code shows how to concatenate two 1-dimensional arrays:

import numpy as np

#create two arrays
arr1 = np.array([1, 2, 3, 4, 5])
arr2 = np.array([6, 7, 8])

#concatentate the two arrays
np.concatenate((arr1, arr2))

[1, 2, 3, 4, 5, 6, 7, 8]

The following code shows how to concatenate two 2-dimensional arrays:

import numpy as np

#create two arrays
arr1 = np.array([[3, 5], [9, 9], [12, 15]])
arr2 = np.array([[4, 0]])

#concatentate the two arrays
np.concatenate((arr1, arr2), axis=0)

array([[3, 5],
       [9, 9],
       [12, 15],
       [4, 0]])

#concatentate the two arrays and flatten the result
np.concatenate((arr1, arr2), axis=None)

array([3, 5, 9, 9, 12, 15, 4, 0])

Example 2: Concatenate More Than Two Arrays

We can use similar code to concatenate more than two arrays:

import numpy as np

#create four arrays
arr1 = np.array([[3, 5], [9, 9], [12, 15]])
arr2 = np.array([[4, 0]])
arr3 = np.array([[1, 1]])
arr4 = np.array([[8, 8]])

#concatentate all the arrays
np.concatenate((arr1, arr2, arr3, arr4), axis=0)

array([[3, 5],
       [9, 9],
       [12, 15],
       [4, 0],
       [1, 1],
       [8, 8]])

#concatentate all the arrays and flatten the result
np.concatenate((arr1, arr2, arr3, arr4), axis=None)

array([3, 5, 9, 9, 12, 15, 4, 0, 1, 1, 8, 8])

The following tutorials explain how to perform similar operations in NumPy:

Cite this article

stats writer (2025). How to Concatenate Arrays in Python (With Examples). PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-concatenate-arrays-in-python-with-examples/

stats writer. "How to Concatenate Arrays in Python (With Examples)." PSYCHOLOGICAL SCALES, 6 Dec. 2025, https://scales.arabpsychology.com/stats/how-to-concatenate-arrays-in-python-with-examples/.

stats writer. "How to Concatenate Arrays in Python (With Examples)." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-concatenate-arrays-in-python-with-examples/.

stats writer (2025) 'How to Concatenate Arrays in Python (With Examples)', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-concatenate-arrays-in-python-with-examples/.

[1] stats writer, "How to Concatenate Arrays in Python (With Examples)," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, December, 2025.

stats writer. How to Concatenate Arrays in Python (With Examples). PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top