MCPcopy Index your code
hub / github.com/numpy/numpy / setxor1d

Function setxor1d

numpy/lib/_arraysetops_impl.py:763–803  ·  view source on GitHub ↗

Find the set exclusive-or of two arrays. Return the sorted, unique values that are in only one (not both) of the input arrays. Parameters ---------- ar1, ar2 : array_like Input arrays. assume_unique : bool If True, the input arrays are both assumed to b

(ar1, ar2, assume_unique=False)

Source from the content-addressed store, hash-verified

761
762@array_function_dispatch(_setxor1d_dispatcher)
763def setxor1d(ar1, ar2, assume_unique=False):
764 """
765 Find the set exclusive-or of two arrays.
766
767 Return the sorted, unique values that are in only one (not both) of the
768 input arrays.
769
770 Parameters
771 ----------
772 ar1, ar2 : array_like
773 Input arrays.
774 assume_unique : bool
775 If True, the input arrays are both assumed to be unique, which
776 can speed up the calculation. Default is False.
777
778 Returns
779 -------
780 setxor1d : ndarray
781 Sorted 1D array of unique values that are in only one of the input
782 arrays.
783
784 Examples
785 --------
786 >>> import numpy as np
787 >>> a = np.array([1, 2, 3, 2, 4])
788 >>> b = np.array([2, 3, 5, 7, 5])
789 >>> np.setxor1d(a,b)
790 array([1, 4, 5, 7])
791
792 """
793 if not assume_unique:
794 ar1 = unique(ar1)
795 ar2 = unique(ar2)
796
797 aux = np.concatenate((ar1, ar2), axis=None)
798 if aux.size == 0:
799 return aux
800
801 aux.sort()
802 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True]))
803 return aux[flag[1:] & flag[:-1]]
804
805
806def _isin(ar1, ar2, assume_unique=False, invert=False, *, kind=None):

Callers 4

test_setxor1dMethod · 0.90
test_setxor1d_uniqueMethod · 0.90
test_manywaysMethod · 0.90

Calls 2

uniqueFunction · 0.70
sortMethod · 0.45

Tested by 4

test_setxor1dMethod · 0.72
test_setxor1d_uniqueMethod · 0.72
test_manywaysMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…