|
|
|
|
|
by shele
1985 days ago
|
|
Ohm, a lot of thought has gone into indexing in Julia. Julia allows indexing by position `A[1,1]`, slicing `A[1:5, :]`, linear indexing `A[1]`, and logical indexing `A[a.==1]`, relative indexing `A[end-1]` and cartesian indexing `A[CartesianIndex(1,1)]`. The way Julia combines these in a mostly non-conflicting and non-confusing manner is a major engineering feat. For example the following rule was found to be the just the right balance between permissive and strict behaviour: * You are permitted to index into arrays with more indices than dimensions, but all trailing indices must be 1. * You are permitted to index into arrays with fewer indices than dimensions, but the length of all the omitted dimensions must be 1. |
|