As has been discussed here in the past, "dimension" may be an ambiguous
term. A matrix has two dimensions, so you're circularly shifting the first
dimension by 2 (which has no effect since the rows are identical) and the
second by 1 (which shifts [1 2 3 4 5] to [5 1 2 3 4]). There are no third,
fourth, or fifth dimensions, so those dimensions are not altered.
If you want to circularly shift each row, you can do that with:
shifts = [2, 1, 1, 1, 1]
d = similar(c)
for i = 1:size(c, 2)
d[i, :] = circshift(c[i, :], (0, shifts[i]))
end
julia> d
5x5 Array{Int64,2}:
4 5 1 2 3
5 1 2 3 4
5 1 2 3 4
5 1 2 3 4
5 1 2 3 4
(This could also be done more efficiently with an explicit loop.)
Simon
On Thursday, October 16, 2014 7:33:32 PM UTC-4, Arch Call wrote:
>
> I am trying to use this function little luck.
>
> ======== manual definition ========
> circshift(A, shifts)
> Circularly shift the data in an array. The second argument is a vector
> giving the amount to shift in each dimension
> ==============================
>
> Sample script with test data
> ======================
> module MyModule
> #-- attempting to use circshift to rearrange columns
> numrows = 5
> a1 = fill(1,numrows,1)
> a2 = fill(2,numrows,1)
> a3 = fill(3,numrows,1)
> a4 = fill(4,numrows,1)
> a5 = fill(5,numrows,1)
> c = hcat(a1,a2,a3,a4,a5)
> println(c)
> d = circshift(c,[2,1,1,1,1])
> println(d)
> end
>
> I just cannot get my head around on how the shifts work for each dimension.
>
> Can anyone elaborate?...Thanks Archie
>
> Sample output
> ============
>
> 5 1 2 3 4
> 5 1 2 3 4
> 5 1 2 3 4
> 5 1 2 3 4
> 5 1 2 3 4
>
>
>