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)
| 761 | |
| 762 | @array_function_dispatch(_setxor1d_dispatcher) |
| 763 | def 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 | |
| 806 | def _isin(ar1, ar2, assume_unique=False, invert=False, *, kind=None): |
searching dependent graphs…