Is there a function that easily shifts arrays of indices? For example, I have an array x =[-2, -1, 0, 1, 2]
and want to make it into an array of indices y =[4, 5, 1, 2, 3]
.
I thought about Offset arrays, but I don't really need the whole array shifted and the shift of x
changes depending on the input values.
Something like?
mod1.(x .+ 6, 5)
Have you see CircularArrays.jl? Not sure if this can totally address your usecase or not.
julia> using CircularArrays
julia> a = CircularVector([:a, :b, :c, :d, :e]);
julia> getindex.((a,), [-2, -1, 0, 1, 2] .+ 1)
5-element Vector{Symbol}:
:d
:e
:a
:b
:c
julia> getindex.((a,), [4, 5, 1, 2, 3])
5-element Vector{Symbol}:
:d
:e
:a
:b
:c
mod1
is perfect! Exactly fits the bill
CircularArrays or OffsetArrays probably would work, but there is only one function that requires this shift and the rest are handled as regular arrays, so I was trying to avoid mixing array types.
Are there packages for shifting/circular arrays that respect linear algebra? For example, if I have a finite difference value vector numbered 0:n, I can multiply it by a matrix that has column indices 0:n as well. Or if I get the eigenvectors of a circularly defined Fourier transform matrix, they are circular vectors.
Wow, I never realized that OffsetArrays.jl didn't work with linear algebra. That's a little disappointing. It should at least deal with multiplication
Last updated: Dec 28 2024 at 04:38 UTC