Hi,
consider the 2d array
x=[j+10*i for i=1:2, j=1:2]
I would like to take a slice along the first and the second dimensions, i.e.
julia> x[1:2,1]
2-element Array{Int64,1}:
11
21
julia> x[1,1:2]
1x2 Array{Int64,2}:
11 12
why is the second result a 2d array? Shouldn't a slice of 2d array with one (the first or the second) index fixed always be a 1d array? I understand, that this somewhat reflects the shape of the slice (the first slice is vertically oriented and the second slice is horizontally oriented). But then, why is the first case a 1d array instead of 2d array? This seems a little bit inconsistent. I consider the following behavior much clearer
julia> x[1:2,1:1]
2x1 Array{Int64,2}:
11
21
julia> x[1:1,1:2]
1x2 Array{Int64,2}:
11 12
julia> x[1:2,1]
2-element Array{Int64,1}:
11 21
julia> x[1,1:2]
2-element Array{Int64,1}:
11 12
This is getting more and more confusing with higher dimensional arrays, when you have to deal with the particular dimension along which you make a slice. Imagine dealing with x[1,1,1,1:3,1,1] with the range '1:3' possibly exchanging places with fixed index '1' in the same code. Do I have to count the commas each time I want a slice of high-dimensional array and then deal with the slices as they were 1d, 2d, 3d, ... kd arrays (when effectively they are all 1d arrays)? I think counting colons is much more intuitive and better reflects the dimensions of the result. This problem extends to 2d slices of 3d arrays
y=[j+10*i+100*k for i=1:2, j=1:2, k=1:2]
for which slicing gives
julia> y[1,1:2,1:2]
1x2x2 Array{Int64,3}:
[:, :, 1] =
111 112
[:, :, 2] =
211 212
julia> y[1:2,1,1:2]
2x1x2 Array{Int64,3}:
[:, :, 1] =
111
121
[:, :, 2] =
211
221
julia> y[1:2,1:2,1]
2x2 Array{Int64,2}:
111 112
121 122
with the last case clearly distinguishing itself from the two other cases.