Reputation: 2381
How can I quickly generate matrix by row from range?
For example, given
my_example_matrix = [[1 2 3]
[4 5 6]
[7 8 9]]
How can I generate the matrix fastly by using range 1:9
?
Best.
Upvotes: 2
Views: 176
Reputation: 4510
This is quick in a way because no part of it allocates memory, so the length of the range won't matter.
julia> transpose(reshape(1:9, (3, 3)))
3×3 LinearAlgebra.Transpose{Int64,Base.ReshapedArray{Int64,2,UnitRange{Int64},Tuple{}}}:
1 2 3
4 5 6
7 8 9
Upvotes: 2