Indexing behavior - BenoitKnecht/julia GitHub Wiki
Stefan's thoughts on indexing behavior:
x = [[11,12,13],[21,22,23],[31,32,33]] # a 2-tensor, i.e. a matrixHere's some of the slices notations and results I'm thinking of:
x[1,] == [11,12,13]
x[,1] == [11,21,31]
x[[1,3],] == [[11,12,13],[31,32,33]]
x[,[1,3]] == [[11,13],[21,23],[31,33]]
x[[1,3],[1,2]] ==
(x[[1,3],])[,[1,2]] ==
(x[,[1,2]])[[1,3],] ==
[[11,12],[31,32]]
Slicing an index with a scalar, i.e. a 0-tensor, reduces the rank of the resulting tensor by 1; slicing by a vector, i.e. a 1-tensor, keeps it the same. What about higher rank tensors for slicing? I'm thinking this should *increase* the rank of the resulting tensor by essentially looping over vector slices. Let me try to give an example.
x = [a,b,c]
x[[[1,3],[2,3]]] ==
[x[[1,3]],x[[2,3]]] ==
[[x[1],x[3]],[x[2],x[3]]] ==
[[a,c],[b,c]]
Note the way the application of indexing and bracketing commute as operators. Also note that the general rule is that the tensor rank of a slice operations output is the sum of the ranks of the slices themselves. For example, if all slices are scalars, they all have rank zero, so the output has rank zero---i.e. it is a scalar. If all slices are : which has rank 1, then the output is identical to the input object and of course has the same rank.