MCPcopy Index your code
hub / github.com/numpy/numpy / setxor1d

Function setxor1d

numpy/ma/extras.py:1350–1384  ·  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. Examples -------- >>> import numpy as np >>> ar1 = np.ma.array

(ar1, ar2, assume_unique=False)

Source from the content-addressed store, hash-verified

1348
1349
1350def setxor1d(ar1, ar2, assume_unique=False):
1351 """
1352 Set exclusive-or of 1-D arrays with unique elements.
1353
1354 The output is always a masked array. See `numpy.setxor1d` for more details.
1355
1356 See Also
1357 --------
1358 numpy.setxor1d : Equivalent function for ndarrays.
1359
1360 Examples
1361 --------
1362 >>> import numpy as np
1363 >>> ar1 = np.ma.array([1, 2, 3, 2, 4])
1364 >>> ar2 = np.ma.array([2, 3, 5, 7, 5])
1365 >>> np.ma.setxor1d(ar1, ar2)
1366 masked_array(data=[1, 4, 5, 7],
1367 mask=False,
1368 fill_value=999999)
1369
1370 """
1371 if not assume_unique:
1372 ar1 = unique(ar1)
1373 ar2 = unique(ar2)
1374
1375 aux = ma.concatenate((ar1, ar2), axis=None)
1376 if aux.size == 0:
1377 return aux
1378 aux.sort()
1379 auxf = aux.filled()
1380# flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0
1381 flag = ma.concatenate(([True], (auxf[1:] != auxf[:-1]), [True]))
1382# flag2 = ediff1d( flag ) == 0
1383 flag2 = (flag[1:] == flag[:-1])
1384 return aux[flag2]
1385
1386
1387def in1d(ar1, ar2, assume_unique=False, invert=False):

Callers 2

test_setxor1dMethod · 0.90
test_setxor1d_uniqueMethod · 0.90

Calls 3

uniqueFunction · 0.70
sortMethod · 0.45
filledMethod · 0.45

Tested by 2

test_setxor1dMethod · 0.72
test_setxor1d_uniqueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…