If you have an array of arrays, you can join them into a 2d array as follows:
a = fill(ones(10), 10)
A = hcat(a...)
How can you do the reverse?
If you have an array of arrays, you can join them into a 2d array as follows:
a = fill(ones(10), 10)
A = hcat(a...)
How can you do the reverse?
Thanks. I assumed this was a duplicate question but couldn’t find a relevant thread. In short, the solution is:
[A[:, i] for i in 1:size(A, 2)]
Edit: Thanks @DNF
Since Julia 1.1, we also have eachrow
for this.
If the Columns are short, consider reinterpret to reinterpret the matrix as an array off SVectors.
The inverse of hcat
would be eachcolumn
or [A[:, i] for i in 1:size(A,2)]
.
BTW, reduce(hcat, a)
is preferable to splatting for efficiency reasons.