circshift does what you want according to the accepted answer. However, to add to this, you can also manually manipulate indexes:
julia> a = [1,2,3,4]; julia> a[[2:end; 1]] |> show [2,3,4,1] julia> a[[3:end; 1:2]] |> show [3,4,1,2]
In fact, what you are doing here is indexing the integers 'linear' , so the number of elements can be more than 4 (i.e. the same positions may be available several times or not at all):
julia> a[[3:end; 1:2; 1; 2; 2; 1]] |> show [3,4,1,2,1,2,2,1] julia> a[[1:end; end-1:-1:1]] |> show [1,2,3,4,3,2,1]
The same applies to arrays with a higher dimension:
julia> b = [1 2 3 4; 2 3 4 5; 3 4 5 6; 4 5 6 7]; julia> b[[2:end; 1], [1:3; 2:end; 1]] 4ร7 Array{Int64,2}: 2 3 4 3 4 5 2 3 4 5 4 5 6 3 4 5 6 5 6 7 4 1 2 3 2 3 4 1
Tasos papastylianou
source share