# One column arrays and vectors

**URL:** <https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321>\
**Category:** General Usage\
**Created:** [September 9, 2020, 11:24am UTC](https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321 "2020-09-09T11:24:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 9, 2020, 11:24am UTC](https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321/1 "2020-09-09T11:24:09Z")

</div>

I have a function that accepts your choice of one column arrays or vectors. Now I want to add a method and dispatch on one column arrays or vectors to get my original method. How do I create a type to let me do that?

This sorta works

```julia
KT=Union{Vector{T}, Array{T,2}} where T <: Real

```

but does not limit the array to a single column. I’m clearly missing something. Am I trying to do the impossible?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 9, 2020, 11:32am UTC](https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321/2 "2020-09-09T11:32:40Z")

</div>

The size of an array is not known at compile time, so you can’t dispatch on it. You could just assert in your code that `size(a, 2) == 1`, or you can always convert matrices into an `AbstractVector` with `vec`, so you could just accept `AbstractVector` only. BTW, Base already defines what you’re defining, with the exception of accepting `Any` instead of `Real` as `VecOrMat`. So your definition would be equivalent to `VecOrMat{<:Real}`.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [September 9, 2020, 11:40am UTC](https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321/3 "2020-09-09T11:40:27Z")

</div>

Fair enough. I was afraid of that.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [September 9, 2020, 1:31pm UTC](https://discourse.julialang.org/t/one-column-arrays-and-vectors/46321/4 "2020-09-09T13:31:59Z")

</div>

You can only dispatch on number of axes with standard `Array`. You can dispatch on size with arrays from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl)
