Juliaで配列をシフトする方法として、circshiftというものがありますので紹介します。
1次元配列
左にシフト
array = Array(1:6)
println(array)
a = circshift(array, -1)
println(a)
[1, 2, 3, 4, 5, 6]
[2, 3, 4, 5, 6, 1]
右にシフト
array = Array(1:6)
println(array)
a = circshift(array, 1)
println(a)
[1, 2, 3, 4, 5, 6]
[6, 1, 2, 3, 4, 5]
2次元配列
上にシフト
array = reshape(1:9,(3,3))
println(array)
a = circshift(array,-1)
println(a)
[1 4 7; 2 5 8; 3 6 9]
[2 5 8; 3 6 9; 1 4 7]
下にシフト
array = reshape(1:9,(3,3))
println(array)
a = circshift(array,1)
println(a)
[1 4 7; 2 5 8; 3 6 9]
[3 6 9; 1 4 7; 2 5 8]
左にシフト
array = reshape(1:9,(3,3))
println(array)
a = circshift(array,(0,-1))
println(a)
[1 4 7; 2 5 8; 3 6 9]
[7 1 4; 8 2 5; 9 3 6]
右にシフト
array = reshape(1:9,(3,3))
println(array)
a = circshift(array,(0,-1))
println(a)
[1 4 7; 2 5 8; 3 6 9]
[4 7 1; 5 8 2; 6 9 3]