In Julia, the vectorized dot operator is used to apply a binary operation on each element of the array or vector. It is useful when we want to apply a particular binary operation on the entire array of elements. For example, if want to multiply each element in the array with number 5
, we can use the vectorized dot operator as follows.
Input: [1, 2, 3, 4] .* 5
Output: [5, 10, 15, 20]
array . binary_operation
Let us take a look at an example of this.
#given arrayarr = [1, 2, 3, 4]# usage of vectorized dot operatorprintln(arr .* 5)
In the above code snippet,
Line 2: We declare and initialize an array of numbers and assign it to variable, arr
.
Line 5: We multiply each element in the array arr
with 5
using the vectorized dot operator.
Free Resources