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

**URL:** <https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914>\
**Category:** General Usage\
**Created:** [November 23, 2018, 4:26pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914 "2018-11-23T16:26:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balance37](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Balance37](https://discourse.julialang.org/u/Balance37)\
**Post date:** [November 23, 2018, 4:26pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/1 "2018-11-23T16:26:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)\
**Post date:** [November 23, 2018, 4:42pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/2 "2018-11-23T16:42:56Z")

</div>

try `vec`

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [November 23, 2018, 5:04pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/3 "2018-11-23T17:04:06Z")

</div>

Or use the colon, `:`, notation:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 23, 2018, 5:12pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/4 "2018-11-23T17:12:27Z")

</div>

> [@Seif\_Shebl](#):
>
> Or use the colon, `:` , notation:

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

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [November 23, 2018, 6:04pm UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/5 "2018-11-23T18:04:13Z")

</div>

MATLAB ghost is still chasing some of us 😃!

---

<div class="post-metadata">

**Author:** ![Balance37](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Balance37](https://discourse.julialang.org/u/Balance37)\
**Post date:** [November 27, 2018, 2:52am UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/6 "2018-11-27T02:52:19Z")

</div>

Thanks, it solved my problem

---

<div class="post-metadata">

**Author:** ![Balance37](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Balance37](https://discourse.julialang.org/u/Balance37)\
**Post date:** [November 27, 2018, 2:53am UTC](https://discourse.julialang.org/t/having-a-vector-1-dimension-array-but-it-has-2-dimensions/17914/7 "2018-11-27T02:53:13Z")

</div>

Lol, lucky us
