Skip to content

Commit 1b25d1e

Browse files
nathanrboyermbaumanbarucdenjishnubfingolfin
authored
Add CartesianIndex to getindex docstring (#51567)
Co-authored-by: Matt Bauman <[email protected]> Co-authored-by: Denis Barucic <[email protected]> Co-authored-by: Jishnu Bhattacharya <[email protected]> Co-authored-by: Max Horn <[email protected]>
1 parent c7eb766 commit 1b25d1e

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

base/abstractarray.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,8 +1274,11 @@ end
12741274
"""
12751275
getindex(A, inds...)
12761276
1277-
Return a subset of array `A` as specified by `inds`, where each `ind` may be,
1278-
for example, an `Int`, an [`AbstractRange`](@ref), or a [`Vector`](@ref).
1277+
Return a subset of array `A` as selected by the indices `inds`.
1278+
1279+
Each index may be any [supported index type](@ref man-supported-index-types), such
1280+
as an [`Integer`](@ref), [`CartesianIndex`](@ref), [range](@ref Base.AbstractRange), or [array](@ref man-multi-dim-arrays) of supported indices.
1281+
A [:](@ref Base.Colon) may be used to select all elements along a specific dimension, and a boolean array (e.g. an `Array{Bool}` or a [`BitArray`](@ref)) may be used to filter for elements where the corresponding index is `true`.
12791282
12801283
When `inds` selects multiple elements, this function returns a newly
12811284
allocated array. To index multiple elements without making a copy,
@@ -1303,6 +1306,27 @@ julia> getindex(A, 2:4)
13031306
3
13041307
2
13051308
4
1309+
1310+
julia> getindex(A, 2, 1)
1311+
3
1312+
1313+
julia> getindex(A, CartesianIndex(2, 1))
1314+
3
1315+
1316+
julia> getindex(A, :, 2)
1317+
2-element Vector{Int64}:
1318+
2
1319+
4
1320+
1321+
julia> getindex(A, 2, :)
1322+
2-element Vector{Int64}:
1323+
3
1324+
4
1325+
1326+
julia> getindex(A, A .> 2)
1327+
2-element Vector{Int64}:
1328+
3
1329+
4
13061330
```
13071331
"""
13081332
function getindex(A::AbstractArray, I...)

0 commit comments

Comments
 (0)