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

Function setxor1d

numpy/ma/extras.py:1262–1286  ·  view source on GitHub ↗

Set exclusive-or of 1-D arrays with unique elements. The output is always a masked array. See `numpy.setxor1d` for more details. See Also -------- numpy.setxor1d : Equivalent function for ndarrays.

(ar1, ar2, assume_unique=False)

Source from the content-addressed store, hash-verified

1260
1261
1262def setxor1d(ar1, ar2, assume_unique=False):
1263 """
1264 Set exclusive-or of 1-D arrays with unique elements.
1265
1266 The output is always a masked array. See `numpy.setxor1d` for more details.
1267
1268 See Also
1269 --------
1270 numpy.setxor1d : Equivalent function for ndarrays.
1271
1272 """
1273 if not assume_unique:
1274 ar1 = unique(ar1)
1275 ar2 = unique(ar2)
1276
1277 aux = ma.concatenate((ar1, ar2))
1278 if aux.size == 0:
1279 return aux
1280 aux.sort()
1281 auxf = aux.filled()
1282# flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0
1283 flag = ma.concatenate(([True], (auxf[1:] != auxf[:-1]), [True]))
1284# flag2 = ediff1d( flag ) == 0
1285 flag2 = (flag[1:] == flag[:-1])
1286 return aux[flag2]
1287
1288
1289def in1d(ar1, ar2, assume_unique=False, invert=False):

Callers 1

test_setxor1dMethod · 0.90

Calls 3

sortMethod · 0.80
uniqueFunction · 0.70
filledMethod · 0.45

Tested by 1

test_setxor1dMethod · 0.72