A common method to generate and initialize vectors using ones, zeros, or random values, is, e.g., `ones(N,1)`

.

However, in Julia, such initializations result in a matrix type (!) rather than a vector:

julia> VERSION

v"1.4.1"

julia> ones(2,1)

**2×1 Array{Float64,2}:**

1.0

1.0

julia> ones(1,2)

**1×2 Array{Float64,2}:**

1.0 1.0

This is also true for other functions such as zeros and randn. Usually this must not cause any problems. However, functions such as `Diagonal`

change their behaviour based on the input type. This causes newbie (perhaps also for experienced users) problems. Furthermore, each call to ones, etc. has to be wrapped in a vec: `Diagonal(vec(ones(2,1)))`

which is against Julia’s aim of better code clarity.

What are the best practices for generating vectors of zeros, ones, etc., so that the result is of vector type?

Definitely, I would prefer the functions to return vectors when the requested dimension unambiguously says so.