2 dimensional array to one dimensional

how can i make 2 dimensional array to one dimensional

Like

arr = [[1,2], [3,4]]
To
one, two, three, four = something to transport

NB: Is like numpy ravel method

You’re looking for vec

help?> vec
search: vec Vector VecOrMat VecElement BitVector DenseVector DenseVecOrMat StridedVector StridedVecOrMat AbstractVector

  vec(a::AbstractArray) -> AbstractVector

  Reshape the array a as a one-dimensional column vector. Return a if it is already an AbstractVector. The resulting
  array shares the same underlying data as a, so it will only be mutable if a is mutable, in which case modifying one
  will also modify the other.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> a = [1 2 3; 4 5 6]
  2×3 Array{Int64,2}:
   1  2  3
   4  5  6

  julia> vec(a)
  6-element Array{Int64,1}:
   1
   4
   2
   5
   3
   6

  julia> vec(1:3)
  1:3

  See also reshape.
1 Like

Iterators.flatten (which you can materialize with collect):

julia> arr = [[1,2], [3,4]];                                              
                                                                          
julia> it = Iterators.flatten(arr)                                        
Base.Iterators.Flatten{Array{Array{Int64,1},1}}(Array{Int64,1}[[1, 2], [3,
 4]])                                                                     
                                                                          
julia> collect(it)                                                        
4-element Array{Int64,1}:                                                 
 1                                                                        
 2                                                                        
 3                                                                        
 4

Note though that arr from your example is not two dimensional; it is a one dimensional array containing one dimensional arrays.

5 Likes

thank you so much for help

thank you so much for help

julia> arr = [[1,2], [3,4]]
2-element Array{Array{Int64,1},1}:
 [1, 2]
 [3, 4]

julia> vcat(arr...)
4-element Array{Int64,1}:
 1
 2
 3
 4

It’s work too…
thank you