Why size(vector, 2) return 1?

I was wondering if there is a reason for this design decision.

Code example:

julia> v = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3

julia> size(v, 1)
3

julia> size(v, 2)
1

Even:

julia> size(v, 3) # etc.  just do: size(v) to see "size" and number of dimensions.
1

I guess since it’s allowed by adding arbitrary many dimensions, to index like:

julia> v[2, 1, 1] # etc.

1

https://docs.julialang.org/en/v1/manual/arrays/#Omitted-and-extra-indices

Similarly, more than N indices may be provided if all the indices beyond the dimensionality of the array are 1 (or more generally are the first and only element of axes(A, d) where d is that particular dimension number). This allows vectors to be indexed like one-column matrices.

1 Like