|
Size: 662
Comment:
|
← Revision 3 as of 2023-07-01 14:42:44 ⇥
Size: 1327
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 12: | Line 12: |
A single-dimensional array is called a '''vector'''. |
|
| Line 41: | Line 43: |
| If elements are delimited by single semicolons (`;`) or newlines, they are '''vertically concatenated'''. This usually still results in a vector. {{{ julia> [1:2; 4:5] 4-element Vector{Int64}: 1 2 4 5 julia> [1:2 4:5 6] 5-element Vector{Int64}: 1 2 4 5 6 }}} If elements are delimited by tabs or spaces or double semicolons, they are '''horizontally concatenated'''. This usually creates a '''matrix''', a multi-dimensional array. {{{ julia> [1:2 4:5 7:8] 2×3 Matrix{Int64}: 1 4 7 2 5 8 julia> [1 2 3] 1×3 Matrix{Int64}: 1 2 3 }}} |
Julia Arrays
Julia supports single- and multi-dimensional arrays.
Contents
Declaration
A single-dimensional array is called a vector.
julia> [1,2,3]
3-element Vector{Int64}:
1
2
3Arrays take the common type of all their elements. If the elements are not of the same type but have a common promotion type, the elements are recast.
julia> [1, 2.3, 4//5]
3-element Vector{Float64}:
1.0
2.3
0.8Elements can also be explicitly recast at declaration of an array.
julia> Float32[1, 2.3, 4//5]
3-element Vector{Float32}:
1.0
2.3
0.8If elements are delimited by single semicolons (;) or newlines, they are vertically concatenated. This usually still results in a vector.
julia> [1:2; 4:5]
4-element Vector{Int64}:
1
2
4
5
julia> [1:2
4:5
6]
5-element Vector{Int64}:
1
2
4
5
6If elements are delimited by tabs or spaces or double semicolons, they are horizontally concatenated. This usually creates a matrix, a multi-dimensional array.
julia> [1:2 4:5 7:8]
2×3 Matrix{Int64}:
1 4 7
2 5 8
julia> [1 2 3]
1×3 Matrix{Int64}:
1 2 3