Appart from allocating a new vector and filling its values one by one with the one of my matrix, how would I resize / refill a matrix of size n x m to a vector of size n x m generalizing the following example:
julia> example_matrix = [i+j for i in 1:3, j in 1:4]
3×4 Array{Int64,2}:
2 3 4 5
3 4 5 6
4 5 6 7
julia> res_vect = [2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7]
12-element Array{Int64,1}:
2
3
4
3
4
5
4
5
6
5
6
7
An idea I had is:
res_vect = Int[]
for j in 1:size(example_matrix,2)
res_vect = vcat(res_vect, example_matrix[:,j])
end
I have the feeling it is not the optimal way yet I could not explain why...
res_vect = [], unless you have a very good reason.[]creates aVector{Any}, which will poison the other arrays you concatenate it with. Writing[]is a huge red flag for performance. You should writeInt[]if you intend the array to containInts. - DNF