Monday, October 13, 2025
HomeLanguagesnumpy.concatenate() function | Python

numpy.concatenate() function | Python

numpy.concatenate() function concatenate a sequence of arrays along an existing axis.

Syntax : numpy.concatenate((arr1, arr2, …), axis=0, out=None)
Parameters :
arr1, arr2, … : [sequence of array_like] The arrays must have the same shape, except in the dimension corresponding to axis.
axis : [int, optional] The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. Default is 0.
out : [ndarray, optional] If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified.
Return : [ndarray] The concatenated array.

Code #1 :




# Python program explaining
# numpy.concatenate() function
  
# importing numpy as geek 
import numpy as geek
  
arr1 = geek.array([[2, 4], [6, 8]])
arr2 = geek.array([[3, 5], [7, 9]])
  
gfg = geek.concatenate((arr1, arr2), axis = 0)
  
print (gfg)


Output :

[[2 4]
 [6 8]
 [3 5]
 [7 9]]

 
Code #2 :




# Python program explaining
# numpy.concatenate() function
  
# importing numpy as geek 
import numpy as geek
  
arr1 = geek.array([[2, 4], [6, 8]])
arr2 = geek.array([[3, 5], [7, 9]])
  
gfg = geek.concatenate((arr1, arr2), axis = 1)
  
print (gfg)


Output :

[[2 4 3 5]
 [6 8 7 9]]

 
Code #3 :




# Python program explaining
# numpy.concatenate() function
  
# importing numpy as geek 
import numpy as geek
  
arr1 = geek.array([[2, 4], [6, 8]])
arr2 = geek.array([[3, 5], [7, 9]])
  
gfg = geek.concatenate((arr1, arr2), axis = None)
  
print (gfg)


Output :

[2 4 6 8 3 5 7 9]
RELATED ARTICLES

Most Popular

Dominic
32353 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6721 POSTS0 COMMENTS
Nicole Veronica
11885 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11943 POSTS0 COMMENTS
Shaida Kate Naidoo
6841 POSTS0 COMMENTS
Ted Musemwa
7105 POSTS0 COMMENTS
Thapelo Manthata
6797 POSTS0 COMMENTS
Umr Jansen
6798 POSTS0 COMMENTS