June 2019
Intermediate to advanced
218 pages
5h 19m
English
I hope that in your explorations of Julia, you have come across array broadcasting. This is the ability to perform an operation on each element of an array, rather than on the array as a whole, such as computing the square root of every element of a vector, as shown in the following code:
julia> a=collect(1:4);julia> sqrt.(a)4-element Array{Float64,1}: 1.0 1.4142135623730951 1.7320508075688772 2.0
More generally, it allows operations between arrays of different shapes, such as adding a vector to every column in a matrix, as follows:
julia> b=reshape(1:8, 4, 2)4×2 reshape(::UnitRange{Int64}, 4, 2) with eltype Int64: 1 5 2 6 3 7 4 8julia> b .+ a4×2 Array{Int64,2}: 2 6 4 8 6 10 8 12
For the most part, broadcasting is a great syntactic ...
Read now
Unlock full access