Understanding broadcasting in Julia
Julia has a very powerful piece of built-in functionality for vectorizing operations. It is very simple, as you only need to add a dot, .
, after the name of a function, or annotate an expression with @.
to vectorize it. In this recipe, we will explain in detail how this mechanism works.
A common operation in data science is getting a subset of the original dataset. In this recipe, we will generate a vector and then will randomly select 50% of its odd rows.
Getting ready
Now open your favorite terminal to execute the commands.
Note
In the GitHub repository for this recipe, you will find the commands.txt
file that contains the presented sequence of shell and Julia commands.
How to do it...
We will compare different options for applying to broadcast to a vector of data:
- First, generate the vector we want to work within the Julia console:
julia> x = [1:10;]
10-element Array{Int64,1}:
1
2
3
4
5
6
7
8
9
10
We have a 10
element column vector. We want...