Skip to content

Commit 38a2478

Browse files
authored
Clarify that boolean array indexing requirements (#164)
We only require that boolean array indexing be supported when the array is the sole index. The previous text was ambiguous, and could be read as supporting boolean arrays plus other non-array indices as part of a larger multidimensional index. However, this is complicated in general, as it can lead to some corner cases. See the discussion in #84. With that being said, it is still an open discussion whether we should allow some subset of boolean array indices along with other non-array indices in the same index. I believe regardless, what we do not want to allow is: - multiple boolean arrays (this requires broadcasting semantics, which are confusing for boolean arrays) - boolean arrays and integers separated by a non-integer index (for example a[b, :, 0] where b is a boolean array). This is the corner case currently implemented by NumPy which we want to avoid for the standard.
1 parent a679857 commit 38a2478

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spec/API_specification/indexing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ _Rationale: this is consistent with bounds-checking for single-axis indexing. An
160160

161161
## Boolean Array Indexing
162162

163-
An array must support indexing via a **single** `M`-dimensional boolean array `B` with shape `S1 = (s1, ..., sM)` according to the following rules. Let `A` be an `N`-dimensional array with shape `S2 = (s1, ..., sM, ..., sN)`.
163+
An array must support indexing where the **sole index** is an `M`-dimensional boolean array `B` with shape `S1 = (s1, ..., sM)` according to the following rules. Let `A` be an `N`-dimensional array with shape `S2 = (s1, ..., sM, ..., sN)`.
164164

165165
- If `N >= M`, then `A[B]` must replace the first `M` dimensions of `A` with a single dimension having a size equal to the number of `True` elements in `B`. The values in the resulting array must be in row-major (C-style order); this is equivalent to `A[nonzero(B)]`.
166166

@@ -184,4 +184,4 @@ The result of an indexing operation (e.g., multi-axis indexing, boolean array in
184184
```{note}
185185
186186
The specified return value behavior includes indexing operations which return a single value (e.g., accessing a single element within a one-dimensional array).
187-
```
187+
```

0 commit comments

Comments
 (0)