Inplace conversion of a (m,n)-array into an m-element array

Julia is column-major, so it’ll be faster to flip your array’s indices and use column-wise slices. Try collect(eachcol(arr)), or eachrow if you really need the rows for some reason.

julia> arr =  rand(1:15, (3,4))
3×4 Array{Int64,2}:
 9  14   9  1
 5   8  13  5
 4  13  15  4

julia> collect(eachcol(arr))
4-element Array{SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true},1}:
 [9, 5, 4]
 [14, 8, 13]
 [9, 13, 15]
 [1, 5, 4]
4 Likes