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)
| 475 | |
| 476 | @array_function_dispatch(_setxor1d_dispatcher) |
| 477 | def 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 | |
| 519 | def _in1d_dispatcher(ar1, ar2, assume_unique=None, invert=None, *, |