Saturday, October 18, 2025
HomeLanguagesnumpy.union1d() function in Python

numpy.union1d() function in Python

numpy.union1d() function find the union of two arrays and return the unique, sorted array of values that are in either of the two input arrays.

Syntax : numpy.union1d(arr1, arr2)

Parameters :
arr1, arr2 : [array_like] Input arrays.

Return : [ndarray] Unique, sorted union of the input arrays.

Code #1 :




# Python program explaining
# numpy.union1d() function
    
# importing numpy as geek 
import numpy as geek 
   
arr1 = [-1, 0, 1]
arr2 = [-2, 0, 2]
   
gfg = geek.union1d(arr1, arr2)
   
print (gfg)


Output :

[-2 -1  0  1  2]

 
Code #2 :




# Python program explaining
# numpy.union1d() function
    
# importing numpy as geek 
import numpy as geek 
   
arr1 = [-3, -2, -1, 0, 1, 2, 3]
arr2 = [-5, -4, -3, 0, 3, 4, 5]
   
gfg = geek.union1d(arr1, arr2)
   
print (gfg)


Output :

[-5 -4 -3 -2 -1  0  1  2  3  4  5]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS