For loop in 2D array

How do I use a for loop to iterate in a 2D array only in a specific row or column?

pseudo code

a = [1 2; 3 4]

for x in a only row[1]
println(x)
end

output

1
2

Thanks!

julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> for i in a[:, 1]
       println(i)
       end
1
3

3 Likes

Note that a[:, 1] makes a copy of that data, which is unnecessary in this case. @view a[:, 1] avoids the copy and should be faster if a is a large matrix.

3 Likes