unique
Find the sorted unique elements of an array. Optionally return indices, inverse mapping, and counts.| Name | Type | Default | Description |
|---|---|---|---|
ar | ArrayLike | — | Input array. It is flattened before computing unique values. |
returnIndex | boolean | false | If true, also return the indices of the first occurrences. |
returnInverse | boolean | false | If true, also return the indices to reconstruct the original from the unique array. |
returnCounts | boolean | false | If true, also return the number of times each unique value appears. |
NDArray when no optional flags are true. Object { values, indices?, inverse?, counts? } when one or more flags are true.
unique_all
Return sorted unique values along with their first-occurrence indices, inverse mapping, and counts. This is a structured-return alternative to callingunique with all flags set to true.
| Name | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Input array. |
values (sorted unique elements), indices (first-occurrence indices), inverse_indices (mapping to reconstruct input), and counts (element counts).
unique_counts
Return sorted unique values and their counts.| Name | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Input array. |
values (sorted unique elements) and counts (number of occurrences of each).
unique_inverse
Return sorted unique values and the inverse mapping to reconstruct the original array.| Name | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Input array. |
values (sorted unique elements) and inverse_indices (indices into values that reconstruct the original).
unique_values
Return only the sorted unique values (no indices, inverse, or counts).| Name | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Input array. |
NDArray — Sorted unique values.
in1d
Test whether each element of a 1D array is also present in a second array. Returns a flattened boolean array.| Name | Type | Default | Description |
|---|---|---|---|
ar1 | ArrayLike | — | Input array to test. |
ar2 | ArrayLike | — | Values to test against. |
invert | boolean | false | If true, invert the result: return true where elements of ar1 are not in ar2. |
NDArray — Boolean array of the same length as ar1 (flattened).
isin
Test whether each element of an array is present in a set of test elements. Unlikein1d, this preserves the shape of the input.
| Name | Type | Default | Description |
|---|---|---|---|
element | ArrayLike | — | Input array to test. |
testElements | ArrayLike | — | Values to test against. Flattened internally. |
invert | boolean | false | If true, return true where elements are not in testElements. |
NDArray — Boolean array with the same shape as element.
intersect1d
Find the sorted intersection of two arrays. Optionally return the indices of the intersecting elements in the original arrays.| Name | Type | Default | Description |
|---|---|---|---|
ar1 | ArrayLike | — | First input array. |
ar2 | ArrayLike | — | Second input array. |
Returns: NDArray of sorted common values. |
union1d
Find the sorted union of two arrays.| Name | Type | Default | Description |
|---|---|---|---|
ar1 | ArrayLike | — | First input array. |
ar2 | ArrayLike | — | Second input array. |
NDArray — Sorted 1D array of unique values present in either input.
setdiff1d
Find the set difference: elements inar1 that are not in ar2.
| Name | Type | Default | Description |
|---|---|---|---|
ar1 | ArrayLike | — | Input array. |
ar2 | ArrayLike | — | Elements to exclude. |
assume_unique | boolean | false | If true, assume both arrays contain unique elements. |
NDArray — Sorted 1D array of values in ar1 that are not in ar2.
setxor1d
Find the symmetric difference: elements that are in either of two arrays, but not in both.| Name | Type | Default | Description |
|---|---|---|---|
ar1 | ArrayLike | — | First input array. |
ar2 | ArrayLike | — | Second input array. |
assume_unique | boolean | false | If true, assume both arrays contain unique elements. |
NDArray — Sorted 1D array of values in exactly one of the two inputs.
trim_zeros
Trim leading and/or trailing zeros from a 1D array.| Name | Type | Default | Description |
|---|---|---|---|
filt | ArrayLike | — | 1D input array. |
trim | string | 'fb' | A string of 'f' (front), 'b' (back), or 'fb' (both). Controls which end(s) to trim. |
NDArray — The trimmed array.