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

Function unique

numpy/ma/extras.py:1267–1314  ·  view source on GitHub ↗

Finds the unique elements of an array. Masked values are considered the same element (masked). The output array is always a masked array. See `numpy.unique` for more details. See Also -------- numpy.unique : Equivalent function for ndarrays. Examples --------

(ar1, return_index=False, return_inverse=False)

Source from the content-addressed store, hash-verified

1265
1266
1267def unique(ar1, return_index=False, return_inverse=False):
1268 """
1269 Finds the unique elements of an array.
1270
1271 Masked values are considered the same element (masked). The output array
1272 is always a masked array. See `numpy.unique` for more details.
1273
1274 See Also
1275 --------
1276 numpy.unique : Equivalent function for ndarrays.
1277
1278 Examples
1279 --------
1280 >>> import numpy as np
1281 >>> a = [1, 2, 1000, 2, 3]
1282 >>> mask = [0, 0, 1, 0, 0]
1283 >>> masked_a = np.ma.masked_array(a, mask)
1284 >>> masked_a
1285 masked_array(data=[1, 2, --, 2, 3],
1286 mask=[False, False, True, False, False],
1287 fill_value=999999)
1288 >>> np.ma.unique(masked_a)
1289 masked_array(data=[1, 2, 3, --],
1290 mask=[False, False, False, True],
1291 fill_value=999999)
1292 >>> np.ma.unique(masked_a, return_index=True)
1293 (masked_array(data=[1, 2, 3, --],
1294 mask=[False, False, False, True],
1295 fill_value=999999), array([0, 1, 4, 2]))
1296 >>> np.ma.unique(masked_a, return_inverse=True)
1297 (masked_array(data=[1, 2, 3, --],
1298 mask=[False, False, False, True],
1299 fill_value=999999), array([0, 1, 3, 1, 2]))
1300 >>> np.ma.unique(masked_a, return_index=True, return_inverse=True)
1301 (masked_array(data=[1, 2, 3, --],
1302 mask=[False, False, False, True],
1303 fill_value=999999), array([0, 1, 4, 2]), array([0, 1, 3, 1, 2]))
1304 """
1305 output = np.unique(ar1,
1306 return_index=return_index,
1307 return_inverse=return_inverse)
1308 if isinstance(output, tuple):
1309 output = list(output)
1310 output[0] = output[0].view(MaskedArray)
1311 output = tuple(output)
1312 else:
1313 output = output.view(MaskedArray)
1314 return output
1315
1316
1317def intersect1d(ar1, ar2, assume_unique=False):

Callers 8

test_unique_onlistMethod · 0.90
test_unique_allmaskedMethod · 0.90
intersect1dFunction · 0.70
setxor1dFunction · 0.70
in1dFunction · 0.70
union1dFunction · 0.70
setdiff1dFunction · 0.70

Calls 1

viewMethod · 0.45

Tested by 3

test_unique_onlistMethod · 0.72
test_unique_allmaskedMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…