Iterating array like numpy?

Does this help?

julia> A = rand(1:10, 3, 2)
3×2 Array{Int64,2}:
 2  9
 1  8
 3  3

julia> for rowindex in axes(A, 1)
       @show A[rowindex, :]
       end
A[rowindex, :] = [2, 9]
A[rowindex, :] = [1, 8]
A[rowindex, :] = [3, 3]

You can use a @view to speed things up in some cases (benchmark!).

If you need an actual iterable for the rows (or their views), that is also easy, just ask.

2 Likes