I want to select unique values that are in only one of the input lists, not in both lists. Is there any Python function for this opertion?

+1 vote

You are trying to perform an exclusive-or (XOR) operation on two arrays. There is a Numpy function **'setxor1d()'** for this operation. This function returns a sorted 1D array of unique values that are in only one of the input arrays.

Here is an example:

>>> import numpy as np

>>> a= np.array([10,12,15,9,8,16,17])

>>> b= np.array([11,12,13,15,18,21,27])>>> np.setxor1d(a,b)

array([ 8, 9, 10, 11, 13, 16, 17, 18, 21, 27])