Having a vector (1-dimension array) but it has 2 dimensions


#1

Hi, I have this “HbeforeDiag” vector, it is supposed to be a 1-dimensional array, and it does say the size of it is (144, 1).
However, the type of it is two dimensions: Array{Float64,2}. And the number of dimensions is 2.
What can I do on this? Thanks.

HbeforeDiag: [43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 43.8266; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0;0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0; 0.0]

size (HbeforeDiag): (144, 1)
typeof(HbeforeDiag): Array{Float64,2}
number of dimension of HbeforeDiag, ndims(HbeforeDiag): 2


#2

try vec

julia> A = copy([1 2 3]')
3×1 Array{Int64,2}:
 1
 2
 3

julia> vec(A)
3-element Array{Int64,1}:
 1
 2
 3

#3

Or use the colon, :, notation:

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

julia> a[:]
6-element Array{Int64,1}:
 1
 4
 2
 5
 3
 6

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

#4

There’s a semantic difference in that [:] makes a copy while vec just gives a view onto the other array.


#5

MATLAB ghost is still chasing some of us :smiley:!


#6

Thanks, it solved my problem


#7

Lol, lucky us