Lesson 17 of 55
10 mins readPython Broadcasting & Dot Syntax (Vectorization)
In Plain English
In Julia, every function can be vectorized automatically using dot broadcasting (f.(x)). Fuse multiple element-wise operations into a single fast memory loop.
Deep Dive: How It Works
Dot Syntax: Adding a dot to any operator or function (e.g. sin.(x), 2 .* x .+ 1) applies it element-wise across arrays.
Loop Fusion: Expressions like @. sin(x) + cos(x) * 2 fuse into a single pass through memory without allocating intermediate arrays.
Broadcasting Dimensions: Combines vectors of differing compatible dimensions (e.g. 1x3 row + 3x1 column = 3x3 matrix).
Core Rules to Remember

Universal Vectorization: No need to write special vectorized versions of functions; simply append a dot.

Automatic Loop Fusion: Dot chains merge into one single loop in machine code, saving allocations.
Live Interactive Example
Hit Run Code to see it liveBroadcasting and Loop Fusion
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Output Console
Click "Run Code" to view the rendered output.
How it works: Loop fusion compiles all operations into a single unallocated traversal.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Broadcast Sqrt Over Vector
Define `nums = [4.0, 9.0, 16.0, 25.0]`.
Compute `roots = sqrt.(nums)`.
Print `"Roots: "` followed by `roots`.
1
2
3
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.