If you just want to apply a binary function to each pair of values ββfrom two lists, you can use map :
f(x,y) = 2x - y^2 julia> map(f, [1, 2, 3], [3, 2, 1]) 3-element Array{Int64,1}: -7 0 5
The .+ And .> Operators also have additional behavior that Singleton broadcast dimensions are passed as follows:
julia> [1, 2, 3] .+ [-1 -2 -3] 3x3 Array{Int64,2}: 0 -1 -2 1 0 -1 2 1 0 julia> rand(3,4) .+ [1, 2, 3] 3x4 Array{Float64,2}: 1.73798 1.84132 1.12923 1.30192 2.10961 2.17835 2.52779 2.3028 3.16457 3.04659 3.67604 3.08869 julia> rand(3,4) .+ [1 2 3 4] 3x4 Array{Float64,2}: 1.40294 2.31384 3.34001 4.60027 1.13289 2.99275 3.50606 4.51049 1.31486 2.7585 3.64655 4.59647
If you also want this behavior, you can use the broadcast function:
julia> broadcast(f, [1 2 3], [3, 2, 1]) 3x3 Array{Int64,2}: -7 -5 -3 -2 0 2 1 3 5
source share