A vector is Julia’s one-dimensional array: an ordered collection of elements accessed by index. It is useful for practical data such as pizza quantities or prices, and Julia starts indexing at 1. section 4.13 section 4.2
Keep these distinctions in mind when building array-based data:
- Write elements separated by commas to create a column vector; separating them with spaces creates a one-row matrix instead. section 4.2
- Use vectors for ordered one-dimensional data and matrices for tables with numbered rows and columns. section 4.2 section 14.1
- Apply functions such as sum, length, sort, and sort! to summarize, measure, order, or modify vector contents. section 4.3
- Use dotted operators such as .*, .+, .-, and ./ for elementwise arithmetic between vectors. section 4.13 section 4.3
Calculating pizza revenue
Store quantities and prices in separate vectors, then multiply matching elements and reduce the result: amounts = [4, 1, 5, 3, 2]; prices = [15.0, 11.5, 13.0, 12.75, 14.25]; revenue = sum(amounts .* prices), producing 203.25. A plain amounts * prices raises a method error because vector multiplication is not automatically defined here. section 4.3
julia> amounts = [4, 1, 5, 3, 2]
5-element Vector{Int64}:
4
1
5
3
2
Inspect a Julia vector directly in the REPL and see its length, element type, and vertically displayed values. section 4.2










