Do you have a clean way of looping through an array?

Post it here. And when I say clean, it doesn’t mean clever. (I usually find that the clever ways of doing things are not the most legible.)

Could you clarify what kind of an array?

a = Array{Float64,3}(undef,3,3,3)
for i in eachindex(a)
    element = a[i]
end
1 Like

I try to follow the manual when possible:

https://docs.julialang.org/en/v1/manual/arrays/#Iteration

Some would also recommend pairs which returns the index and the value.

3 Likes

I like eachindex too!

pairs seems to be more robust than enumerate. That is my impression.

This has been discussed here: Any shortcut to 1:length(myVector)?

1 Like

I never used pairs, but it seems it is a bit more flexible in regards to the index. enumerate always uses a one based linear index.

1 Like