MCPcopy Create free account
hub / github.com/numpy/numpy / setxor1d

Function setxor1d

numpy/lib/arraysetops.py:477–516  ·  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

475
476@array_function_dispatch(_setxor1d_dispatcher)
477def setxor1d(ar1, ar2, assume_unique=False):
478 """
479 Find the set exclusive-or of two arrays.
480
481 Return the sorted, unique values that are in only one (not both) of the
482 input arrays.
483
484 Parameters
485 ----------
486 ar1, ar2 : array_like
487 Input arrays.
488 assume_unique : bool
489 If True, the input arrays are both assumed to be unique, which
490 can speed up the calculation. Default is False.
491
492 Returns
493 -------
494 setxor1d : ndarray
495 Sorted 1D array of unique values that are in only one of the input
496 arrays.
497
498 Examples
499 --------
500 >>> a = np.array([1, 2, 3, 2, 4])
501 >>> b = np.array([2, 3, 5, 7, 5])
502 >>> np.setxor1d(a,b)
503 array([1, 4, 5, 7])
504
505 """
506 if not assume_unique:
507 ar1 = unique(ar1)
508 ar2 = unique(ar2)
509
510 aux = np.concatenate((ar1, ar2))
511 if aux.size == 0:
512 return aux
513
514 aux.sort()
515 flag = np.concatenate(([True], aux[1:] != aux[:-1], [True]))
516 return aux[flag[1:] & flag[:-1]]
517
518
519def _in1d_dispatcher(ar1, ar2, assume_unique=None, invert=None, *,

Callers 3

test_setxor1dMethod · 0.90
test_manywaysMethod · 0.90

Calls 2

sortMethod · 0.80
uniqueFunction · 0.70

Tested by 3

test_setxor1dMethod · 0.72
test_manywaysMethod · 0.72