Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Best way to convert column nested to row nested

Suppose I have an array with nested "columns"

column_nested = [[1, 2], [2, 3], [5, 4]]

How would I convert it into a "rowwise nested array"?

row_nested = [[1, 2, 5], [2, 3, 4]]

My solution: row_nested = collect(eachrow(hcat(column_nested...))) seems a bit verbose and severely messes with types.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Using broadcasting and zip:

julia> row_nested = collect.(zip(column_nested...))
2-element Vector{Vector{Int64}}:
 [1, 2, 5]
 [2, 3, 4]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading