Was not trying to persuade anyone, just wanted to explain that Julia has chosen differently here. All languages, numpy, Matlab and Julia, have their quirks and often taken different decisions regarding syntax and semantics of multi-dimensional arrays. Overall, I feel that Julia is rather consistent, yet often different than numpy or Matlab.
Indeed, the objection applies and it raises an error in that case:
julia> reduce(hcat, [[1, 2, 3], [4, 5]])
ERROR: ArgumentError: number of rows of each array must match (got [3, 2])
That reshape has its own type is merely an implementation detail and its type acts like an (Abstract)Vector in all respects. That the types Vector{Vector} and Matrix are different is not an implementation detail, but a conscious decision in the design of the language - like it or not.
This could be defined, but as others have noted it might be ambiguous. Also keep in mind that Julia is column-major. This has several implications:
-
Slicing rows is inefficient as they are not represented in memory consecutively, which might offer another reason why
test[i]does not extract theith row, but indexes linearly. -
reduce(hcat, [[1, 2, 3], [4, 5, 6]])gives a 3 x 2 matrix, i.e., collects the inner vectors into the rows. Is that what you would want forMatrix([[1, 2, 3], [4, 5, 6]])?