You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Split `unique` into separate functions
* Update copy
* Fix shape guidance
* Add notes
* Rename function to avoid breaking backward compat
* Specify the `values` array data type
The shapes of one or more of output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
21
+
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
22
22
:::
23
23
24
24
Returns the unique elements of an input array `x`.
@@ -29,40 +29,74 @@ Returns the unique elements of an input array `x`.
29
29
30
30
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
-If `True`, the function must also return the number of times each unique element occurs in `x`. Default: `False`.
36
+
-a namedtuple `(values, indices, inverse_indices, counts)` whose
35
37
36
-
-**return_index**: _bool_
38
+
- first element must have the field name `values` and must be an array containing the unique elements of `x`. The array must have the same data type as `x`.
39
+
- second element must have the field name `indices` and must be an array containing the indices (first occurrences) of `x` that result in `values`. The array must have the same shape as `values` and must have the default integer data type.
40
+
- third element must have the field name `inverse_indices` and must be an array containing the indices of `values` that reconstruct `x`. The array must have the same shape as `x` and must have the default integer data type.
41
+
- fourth element must have the field name `counts` and must be an array containing the number of times each unique element occurs in `x`. The returned array must have same shape as `values` and must have the default integer data type.
37
42
38
-
- If `True`, the function must also return the indices (first occurrences) of `x` that result in the unique array. Default: `False`.
43
+
```{note}
44
+
The order of unique elements is not specified and may vary between implementations.
45
+
```
39
46
40
-
-**return_inverse**: _bool_
47
+
(function-unique-inverse)=
48
+
### unique_inverse(x, /)
41
49
42
-
- If `True`, the function must also return the indices of the unique array that reconstruct `x`. Default: `False`.
50
+
Returns the unique elements of an input array `x` and the indices from the set of unique elements that reconstruct `x`.
51
+
52
+
:::{admonition} Data-dependent output shape
53
+
:class: important
54
+
55
+
The shape of one of the output arrays for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
56
+
:::
57
+
58
+
#### Parameters
59
+
60
+
- **x**: _<array>_
61
+
62
+
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
-if `return_counts`, `return_index`, and `return_inverse` are all `False`, an array containing the set of unique elements in `x`; otherwise, a tuple containing two or more of the following arrays (in order):
68
+
- a namedtuple `(values, inverse_indices)` whose
49
69
50
-
-**unique**: _<array>_
70
+
- first element must have the field name `values` and must be an array containing the unique elements of `x`. The array must have the same data type as `x`.
71
+
- second element must have the field name `inverse_indices` and must be an array containing the indices of `values` that reconstruct `x`. The array must have the same shape as `x` and have the default integer data type.
51
72
52
-
- an array containing the set of unique elements in `x`. The returned array must have the same data type as `x`.
73
+
```{note}
74
+
The order of unique elements is not specified and may vary between implementations.
75
+
```
53
76
54
-
```{note}
55
-
The order of elements is not specified, and may vary between implementations.
56
-
```
77
+
(function-unique-values)=
78
+
### unique_values(x, /)
57
79
58
-
- **indices**: _<array>_
80
+
:::{admonition} Data-dependent output shape
81
+
:class: important
82
+
83
+
The shape of the output array for this function depends on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See {ref}`data-dependent-output-shapes` section for more details.
84
+
:::
85
+
86
+
Returns the unique elements of an input array `x`.
59
87
60
-
- an array containing the indices (first occurrences) of `x` that result in `unique`. The returned array must have the default integer data type.
88
+
#### Parameters
89
+
90
+
- **x**: _<array>_
61
91
62
-
- **inverse**: _<array>_
92
+
- input array. If `x` has more than one dimension, the function must flatten `x` and return the unique elements of the flattened array.
93
+
94
+
#### Returns
63
95
64
-
- an array containing the indices of `unique` that reconstruct `x`. The returned array must have the default integer data type.
96
+
- **out**: _<array>_
65
97
66
-
- **counts**: _<array>_
98
+
-an array containing the set of unique elements in `x`. The returned array must have the same data type as `x`.
67
99
68
-
- an array containing the number of times each unique element occurs in `x`. The returned array must have the default integer data type.
100
+
```{note}
101
+
The order of unique elements is not specified and may vary between implementations.
0 commit comments