How to convert CartesianIndex{N} values to Int64

It would be nice to have a simple example that illustrates the problem and that doesn’t rely on any external packages. Something that can be copy pasted into the REPL.

A CartesianIndex represents an index into a potentially multidimensional array. So I’m not sure what converting it to an integer means. Do you mean how to convert it to a “linear index”?

julia> a = rand(2,2)
2×2 Array{Float64,2}:
 0.57097   0.0647051
 0.767868  0.531104

julia> I = LinearIndices(a)
2×2 LinearIndices{2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}:
 1  3
 2  4

julia> I[CartesianIndex(1,2)]
3
5 Likes