Skip to content

Commit

Permalink
Some doc correction.
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Dec 20, 2023
1 parent 2995e51 commit d8d96e1
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions doc/src/manual/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -793,38 +793,46 @@ Indexing by a boolean vector `B` is effectively the same as indexing by the
vector of integers that is returned by [`findall(B)`](@ref). Similarly, indexing
by a `N`-dimensional boolean array is effectively the same as indexing by the
vector of `CartesianIndex{N}`s where its values are `true`. A logical index
must be a vector of the same length as the dimension it indexes into, or it
must be the only index provided and match the size and dimensionality of the
array it indexes into. It is generally more efficient to use boolean arrays as
indices directly instead of first calling [`findall`](@ref).
must be a array of the same shape as the dimension(s) it indexes into, or it
must be the only index provided and match the shape of the one-dimensional
reshaped view of the array it indexes into. It is generally more efficient
to use boolean arrays as indices directly instead of first calling [`findall`](@ref).

```jldoctest
julia> x = reshape(1:16, 4, 4)
4×4 reshape(::UnitRange{Int64}, 4, 4) with eltype Int64:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
julia> x = reshape(1:12, 2, 3, 2)
2×3×2 reshape(::UnitRange{Int64}, 2, 3, 2) with eltype Int64:
[:, :, 1] =
1 3 5
2 4 6
julia> x[[false, true, true, false], :]
2×4 Matrix{Int64}:
2 6 10 14
3 7 11 15
[:, :, 2] =
7 9 11
8 10 12
julia> x[:, [true false; false true; true false]]
2×3 Matrix{Int64}:
1 5 9
2 6 10
julia> mask = map(ispow2, x)
4×4 Matrix{Bool}:
1 0 0 0
1 0 0 0
0 0 0 0
1 1 0 1
2×3×2 Array{Bool, 3}:
[:, :, 1] =
1 0 0
1 1 0
[:, :, 2] =
0 0 0
1 0 0
julia> x[mask]
5-element Vector{Int64}:
1
2
4
8
16
4-element Vector{Int64}:
1
2
4
8
julia> x[vec(mask)] == x[mask] # we can also index with a single Boolean vector
true
```

### Number of indices
Expand Down

0 comments on commit d8d96e1

Please sign in to comment.