Skip to content

Instantly share code, notes, and snippets.

View Oblynx's full-sized avatar

Konstantinos Samaras-Tsakiris Oblynx

  • IDUN Technologies
  • Geneva
View GitHub Profile
@Oblynx
Oblynx / flatten_nested_multidim.jl
Last active August 20, 2020 19:49
Flatten multidimensional nested array in Julia
## SUMMARY ##
# Let `a` be the nested array and `aref` the multidim array we want to recreate:
julia> flatten(x::Array{<:Array,1})= Iterators.flatten(x)|> collect|> flatten
flatten (generic function with 1 method)
julia> flatten(x::Array{<:Number,1})= x
flatten (generic function with 2 methods)
julia> reshape(flatten(a), (4,4,3)) == aref