Returns the unique elements common to both arrays. Masked values are considered equal one to the other. The output is always a masked array. See `numpy.intersect1d` for more details. See Also -------- numpy.intersect1d : Equivalent function for ndarrays. Examples
(ar1, ar2, assume_unique=False)
| 1315 | |
| 1316 | |
| 1317 | def intersect1d(ar1, ar2, assume_unique=False): |
| 1318 | """ |
| 1319 | Returns the unique elements common to both arrays. |
| 1320 | |
| 1321 | Masked values are considered equal one to the other. |
| 1322 | The output is always a masked array. |
| 1323 | |
| 1324 | See `numpy.intersect1d` for more details. |
| 1325 | |
| 1326 | See Also |
| 1327 | -------- |
| 1328 | numpy.intersect1d : Equivalent function for ndarrays. |
| 1329 | |
| 1330 | Examples |
| 1331 | -------- |
| 1332 | >>> import numpy as np |
| 1333 | >>> x = np.ma.array([1, 3, 3, 3], mask=[0, 0, 0, 1]) |
| 1334 | >>> y = np.ma.array([3, 1, 1, 1], mask=[0, 0, 0, 1]) |
| 1335 | >>> np.ma.intersect1d(x, y) |
| 1336 | masked_array(data=[1, 3, --], |
| 1337 | mask=[False, False, True], |
| 1338 | fill_value=999999) |
| 1339 | |
| 1340 | """ |
| 1341 | if assume_unique: |
| 1342 | aux = ma.concatenate((ar1, ar2)) |
| 1343 | else: |
| 1344 | # Might be faster than unique( intersect1d( ar1, ar2 ) )? |
| 1345 | aux = ma.concatenate((unique(ar1), unique(ar2))) |
| 1346 | aux.sort() |
| 1347 | return aux[:-1][aux[1:] == aux[:-1]] |
| 1348 | |
| 1349 | |
| 1350 | def setxor1d(ar1, ar2, assume_unique=False): |
searching dependent graphs…