Vector vs n-element Vector?! Can push to one but not the other

Vector{Real} is a type, not an instance of that type. To construct an empty instance, use the zero-argument constructor.

julia> b = Vector{Real}()
Real[]

julia> push!(b, 0.0)
1-element Vector{Real}:
 0.0

Unlike in Matlab, a vector is not a matrix: the former has one dimension, the latter has two.

julia> Vector <: AbstractMatrix
false

…and a Vector’s length isn’t encoded in its type signature and is free to vary. StaticArrays.jl provides fixed-length vectors.

julia> dump(ones(3))
Array{Float64}((3,)) [1.0, 1.0, 1.0]

julia> dump(@SVector ones(3))
SVector{3, Float64}
  data: Tuple{Float64, Float64, Float64}
    1: Float64 1.0
    2: Float64 1.0
    3: Float64 1.0
6 Likes