MCPcopy
hub / github.com/numpy/numpy / setdiff1d

Function setdiff1d

numpy/lib/_arraysetops_impl.py:1121–1158  ·  view source on GitHub ↗

Find the set difference of two arrays. Return the unique values in `ar1` that are not in `ar2`. Parameters ---------- ar1 : array_like Input array. ar2 : array_like Input comparison array. assume_unique : bool If True, the input arrays are both

(ar1, ar2, assume_unique=False)

Source from the content-addressed store, hash-verified

1119
1120@array_function_dispatch(_setdiff1d_dispatcher)
1121def setdiff1d(ar1, ar2, assume_unique=False):
1122 """
1123 Find the set difference of two arrays.
1124
1125 Return the unique values in `ar1` that are not in `ar2`.
1126
1127 Parameters
1128 ----------
1129 ar1 : array_like
1130 Input array.
1131 ar2 : array_like
1132 Input comparison array.
1133 assume_unique : bool
1134 If True, the input arrays are both assumed to be unique, which
1135 can speed up the calculation. Default is False.
1136
1137 Returns
1138 -------
1139 setdiff1d : ndarray
1140 1D array of values in `ar1` that are not in `ar2`. The result
1141 is sorted when `assume_unique=False`, but otherwise only sorted
1142 if the input is sorted.
1143
1144 Examples
1145 --------
1146 >>> import numpy as np
1147 >>> a = np.array([1, 2, 3, 2, 4, 1])
1148 >>> b = np.array([3, 4, 5, 6])
1149 >>> np.setdiff1d(a, b)
1150 array([1, 2])
1151
1152 """
1153 if assume_unique:
1154 ar1 = np.asarray(ar1).ravel()
1155 else:
1156 ar1 = unique(ar1)
1157 ar2 = unique(ar2)
1158 return ar1[_isin(ar1, ar2, assume_unique=True, invert=True)]

Callers 4

test_setdiff1dMethod · 0.90
test_setdiff1d_uniqueMethod · 0.90
test_manywaysMethod · 0.90

Calls 3

_isinFunction · 0.85
uniqueFunction · 0.70
ravelMethod · 0.45

Tested by 4

test_setdiff1dMethod · 0.72
test_setdiff1d_uniqueMethod · 0.72
test_manywaysMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…