numpy.setxor1d() function in Python
Last Updated :
17 May, 2020
Improve
numpy.setxor1d()
function find the set exclusive-or of two arrays and return the sorted, unique values that are in only one (not both) of the input arrays.
Syntax : numpy.setxor1d(arr1, arr2, assume_unique = False) Parameters : arr1, arr2 : [array_like] Input arrays. assume_unique : [bool] If True, the input arrays are both assumed to be unique, which can speed up the calculation. Default is False. Return : [ndarray] Sorted 1D array of unique values that are in only one of the input arrays.Code #1 :
# Python program explaining
# numpy.setxor1d() function
# importing numpy as geek
import numpy as geek
arr1 = [1, 2, 3, 4]
arr2 = [2, 4, 6, 8]
gfg = geek.setxor1d(arr1, arr2)
print (gfg)
[1 3 6 8]Code #2 :
# Python program explaining
# numpy.setxor1d() function
# importing numpy as geek
import numpy as geek
arr1 = [1, 2, 3, 4, 5]
arr2 = [-2, -1, 0, 1, 2]
gfg = geek.setxor1d(arr1, arr2)
print (gfg)
[-2 -1 0 3 4 5]