An array stores ordered values so you can work with a column of measurements or a whole table instead of handling each value separately. Its elements can be numbers, Booleans, characters, or strings. A one-dimensional array is a vector; a two-dimensional array is a matrix, much like a spreadsheet table. section 4.0 section 4.2
Start with a few practical operations:
- Create a column vector with commas: `amounts = [4, 1, 5, 3, 2]`. Separate values with spaces for a one-row matrix, or separate rows with semicolons for a table. section 4.2
- Read or replace an element with square brackets: `amounts[1]` is `4`. Julia normally starts indexing at 1; `begin` and `end` refer to the first and last positions. An invalid index raises a bounds error. section 4.5
- For larger arrays, use `zeros`, `ones`, `fill`, or `rand`. Specify an element type when needed, and inspect it with `eltype`; `size` and `ndims` describe an array’s shape. section 4.6 section 14.2
- Use `sum` to total elements and `length` to count them. Dotted operators such as `.*` request elementwise arithmetic. `sort` returns a new vector, while `sort!` changes its input. section 4.3
Calculate pizza revenue
Given `amounts = [4, 1, 5, 3, 2]` and `prices = [15.0, 11.5, 13.0, 12.75, 14.25]`, `amounts .* prices` computes revenue for each pizza type. `sum(amounts .* prices)` returns `203.25`. The dot matters: multiplying the two columns with `*` does not specify the intended elementwise operation. section 4.3
Arrays have one element type. A mixed literal such as `["hawaiian", 'S', 10.5]` can have element type `Any`; a tuple instead tracks each element’s type and cannot be changed. For parts of an array, range-based slices make copies; use `@view` when changes should refer to the original data. Arrays also support fast lookup by index, unlike linked lists, though insertion away from the end is not quick. section 4.9 section 14.7 section 12.8







































