An angle measures a turn. People count turns in degrees, 360 to a full circle, but math and code count them in radians, where a full turn is 2π, about 6.28. Mixing the two up is one of the most common bugs in any program that draws, rotates or measures, because the code still runs and gives a wrong answer. In machine learning, the angle between two lists of numbers is how a model tells whether they point the same way, which is the idea behind comparing the meanings of words. This lesson sets up both units, the conversions between them, and the arc a turn sweeps out, so the next two lessons, on sine, cosine and waves, can use radians without a second thought.
What you'll be able to do
Measure a turn in degrees and in radians, and convert between them
Read a radian as the angle whose arc is one radius long, and find an arc's length
Use math.pi, math.radians and math.degrees, and avoid passing degrees where radians are expected
Read the angle between two arrows as how far apart their directions are, as ML does
Quick check
Have a guess before you start. How many degrees are in a quarter turn?
45
180
25
90
Show the answer
90
A full turn is 360°, so a quarter turn is 360 ÷ 4 = 90°: a right angle, like the corner of a page.
The math: measuring a turn
Purpose. Put a number on how far something has turned.
An angle is an amount of turning between two directions. The everyday unit is the degree: a full turn is 360°, a half turn 180°, a quarter turn (a right angle) 90°.
Math uses a second unit, the radian, built from the circle itself. Take a circle of any size and walk along its edge a distance equal to its radius. The angle you've turned through is 1 radian, about 57.3°. A full turn is the whole edge, 2π radii long, so a full turn is 2π radians:
360∘=2π radians180∘=π radians
In plain words: half a turn is π radians, about 3.14. Everything else scales from that.
Quick check
From an earlier lesson: what is 120 as a fraction of 360, in simplest form?
12/36
1/3
3
1/4
Show the answer
1/3
120/360 simplifies by 120 to 1/3. So 120° is a third of a turn, and a third of 2π radians.
Converting through fractions of a turn. The easiest way to convert is to ask what fraction of a full turn the angle is, then take that fraction of 2π. Watch 60° become radians, and the arc it cuts on a circle of radius 2. The picture draws each step on the circle: first the slice of a full turn the arm covers, then the same turn in radians, and last the arc the arm sweeps along the edge.
Try it now
Then set the angle in degrees to 180: the slice is half the circle, and half a turn is π radians. Set the radius to 1 and the arc comes out equal to the angle in radians: each radian sweeps one radius of arc.
Symbols and formula. The two conversions, and the arc:
radians=degrees×180πdegrees=radians×π180s=rθ
In plain words: multiply by π/180 to go to radians, by 180/π to come back. An arc is the radius times the angle in radians.
Common angles are worth knowing by heart: 90° is π/2 ≈ 1.571, 45° is π/4 ≈ 0.785, 30° is π/6 ≈ 0.524, and 360° is 2π ≈ 6.283. The Greek letter θ ("theta") is the usual name for an angle.
Quick check
What is 90° in radians?
90π
π, about 3.142
1/4
π/2, about 1.571
Show the answer
π/2, about 1.571
90° is a quarter turn, and a quarter of 2π is π/2 ≈ 1.571.
Quick check
About how many degrees is 2 radians?
About 180°
2°
About 360°
About 115°
Show the answer
About 115°
2 × 180/π ≈ 2 × 57.3 ≈ 114.6°: a bit more than a quarter turn and a bit.
Why bother with radians? Degrees are a human choice: 360 is handy because it divides evenly by 2, 3, 4, 5, 6, 8, 9, 10 and 12. Radians come from the circle itself, so formulas built on them stay simple. The arc is just s = rθ, with no stray 180 or π in it. The same is true of the formulas for sine, cosine and their rates of change that calculus and every graphics and physics library rely on, which is why code uses radians everywhere.
Negative angles and more than a turn. A negative angle turns the other way (clockwise), and an angle past 360° or 2π just keeps going around. 450° lands in the same direction as 90°, one full turn later. So does −270°, a three-quarter turn the other way. Angles that land in the same direction give the same sine and cosine.
In your own words
In your own words: what is a radian, and why is a full turn 2π of them?
Write a sentence or two, then compare it with a good answer in the lesson.
In Python: code thinks in radians
Purpose. Python's math functions measure angles in radians, so converting is part of using them.
import math
print(math.pi)
print(math.radians(180), math.radians(90))
print(math.degrees(math.pi / 4), math.degrees(1))
It runs right here in your browser, with nothing to install.
math.pi is π. math.radians turns degrees into radians and math.degrees turns radians back. Under the hood they're the formulas above, × π/180 and × 180/π.
Here is the flow's route written out as a function you can step through: degrees to a fraction of a turn, then to radians, then the arc on a circle of radius 2. Press Next until you're inside to_radians, and watch turn and rad take the same values as the cells in the flow.
A named mistake: degrees where radians are expected.math.sin and math.cos (next lesson) take radians. Hand them a number of degrees and they quietly treat it as radians, so the answer is wrong with no error:
import math
print(math.sin(90), math.sin(math.radians(90)))
sin of a quarter turn is exactly 1, but math.sin(90) treats 90 as 90 radians, more than 14 full turns, and gives about 0.894. Whenever an angle comes from people, convert it with math.radians before it reaches a math function.
Worked example
Worked example: a converter that names its units
Write a converter that takes an angle and its unit, and always returns radians, so a caller can't mix them up.
import math
defto_radians(angle, unit):
if unit == "degrees":
return angle * math.pi / 180if unit == "radians":
return angle
returnNoneprint(to_radians(360, "degrees"), to_radians(1.5, "radians"))
print(to_radians(90, "deg"))
In the lesson you can change this and run it.
Making the caller say which unit they mean turns a silent mistake into a visible one. 360 degrees comes back as 2π ≈ 6.283, and 1.5 radians passes through unchanged. An unknown unit, like "deg", returns None instead of a wrong number, so the problem shows up at once. Many real libraries take the unit as an argument for exactly this reason.
Quick check
What does this print?
import math
print(round(math.cos(math.radians(60)), 4), round(math.cos(60), 4))
60 60
-0.9524 0.5
0.5 -0.9524
0.5 0.5
Show the answer
0.5 -0.9524
cos of 60° is 0.5. But math.cos(60) treats 60 as radians, giving about −0.9524: the named mistake.
Quick check
Which line turns 30 degrees into radians?
math.radians(30)
math.degrees(30)
30 * 180 / math.pi
30 / 360
Show the answer
math.radians(30)
math.radians converts degrees to radians: 30 × π/180 ≈ 0.524.
Drill
Convert both ways
Fix the two functions so deg_to_rad(d) gives radians and rad_to_deg(r) gives degrees, then set quarter to a quarter turn in radians.
import math
defdeg_to_rad(d):
return d * 180 / math.pi
defrad_to_deg(r):
return r * math.pi / 180
quarter = deg_to_rad(90)
print(quarter, rad_to_deg(math.pi))
In the lesson, your code is checked as you write it.
In your own words
Why is passing degrees to math.sin such a common bug?
Write a sentence or two, then compare it with a good answer in the lesson.
In AI and ML: the angle between two arrows
Purpose. A list of numbers can be drawn as an arrow from the origin. Machine learning often asks how close two such arrows are in direction, ignoring their lengths. The angle between them answers that.
Three angles mark the scale:
0°: they point the same way. Similar.
90°: they're at right angles. Unrelated.
180°: they point opposite ways. Opposites.
θ=0∘sameθ=90∘unrelatedθ=180∘opposite
In plain words: the smaller the angle between two arrows, the more alike they are.
Lesson 51 computes this angle from the numbers themselves, with the cosine you'll meet next lesson. For now, the picture is the point: word meanings, images and documents become arrows, and similar ones point nearly the same way.
Quick check
Two arrows: one points right, (1, 0), and one points up, (0, 1). What's the angle between them, and what does it mean?
180°: opposite
90°: unrelated
0°: the same
45°: half alike
Show the answer
90°: unrelated
Right and up are a quarter turn apart: 90°, the angle ML reads as "unrelated".
Why direction and not length? Two documents about tents, one short and one long, have word counts that point the same way, even though the long one's numbers are all bigger. Comparing directions treats them as alike, which is what we want. In Python, the angle in radians from lesson 51 will come straight out of math.acos; converting it with math.degrees makes it readable. Say a model measured the angles between three pairs of arrows as π/6, π/2 and 5π/6 radians:
import math
for rad in [math.pi / 6, math.pi / 2, 5 * math.pi / 6]:
print(round(math.degrees(rad)))
The picture draws the three pairs. Arrow a stays put; press Next to swing arrow b from 30° to 90° to 150°.
In the real tools. PyTorch, the library most models are built with, measures angles in radians as well, and converts a whole list of them in one line:
Quick check
What does this print?
import math
print(round(math.degrees(math.pi / 3)), round(math.radians(180), 2))
60 180
3.14 60
60 3.14
1 180
Show the answer
60 3.14
π/3 radians is a sixth of a turn, 60°. 180° is π radians, about 3.14.
Drill
Label pairs of arrows
Angles between three pairs of arrows are given in radians. Convert each to degrees, rounded to a whole number, in a, b and c. Then set most_alike to the letter of the pair that points most nearly the same way.
import math
a = 0.1
b = 1.5708
c = 3.0
most_alike = "c"print(a, b, c, most_alike)
In the lesson, your code is checked as you write it.
In your own words
What would an angle of 175° between two word arrows suggest about the words?
Write a sentence or two, then compare it with a good answer in the lesson.
31Formulas with fractions: clear them firstFreeClearing denominators, cross-multiplying, a letter in the bottom, and reciprocal formulas like 1/R = 1/R₁ + 1/R₂.35 min
37Inverse functions, lines and scalingFreeUndoing a function by making x the subject, domains that allow it, line forms, and unscaling predictions.40 min
38Sequences and sums: find n, a, d and rFreeEvery letter of the arithmetic and geometric formulas as the subject, and an average's window from its decay.40 min
40Review: rearrange anything (algebra)FreeBroken rearrangements to fix, mixed practice from the whole algebra block, a strategy chart, and its formula sheet.35 min
41Coordinates and distanceFreePoints as (x, y), Pythagoras, distance in any number of coordinates, and nearest neighbors.42 min
42Angles, degrees and radiansFreeMeasuring a turn, converting units, arcs, and the angle between two arrows.36 min
43Sine and cosineFreeAcross and up: right triangles, the unit circle, and directions and rotations.42 min
44Waves: height, speed and shiftFreeAmplitude, period and phase, sampling a wave, and position codes in transformers.37 min
68Vector equations: rearranging with arrowsFreeSolving for a vector or a scale, recovering a gradient from two weight snapshots, and an angle from a dot product.40 min
87Counting: choices, orders and groupsFreeThe counting principle, factorials, ordered picks and groups, and why attention's cost grows with the square of the length.43 min
88Probability: from counts to chancesFreeEqually likely outcomes, the complement, distributions, seeded simulation, and a next-word model.43 min
89Combining events: and, or, independentFreeThe or rule, independence, probability trees, drawing with and without replacement, and chains of steps.42 min
100Maximum likelihoodFreeLikelihoods as products, log-likelihoods as sums, grid search, underflow, and the negative log-likelihood loss.45 min
101Linear regression: the best lineFreeResiduals, least squares by formula, three roads to one line, the matrix form, and train versus test error.45 min
109One neuron, start to finishFreeWeighted sum, activation, loss, slopes and update, by hand and in code, and what one straight line can and can't split.45 min
111Training a small networkFreeThe backward pass in matrix form, gradient checks, a full training loop, and reading loss curves.45 min
112The same network in PyTorchFreenn.Sequential with the NumPy weights loaded, the same loss and slopes, then SGD and mini-batches.45 min
113Attention as matrix mathFreeScaled dot-product scores, the causal mask, a row-by-row softmax, and blending value vectors.45 min
114Residual connections and layer normFreeAdding the input back and why its slope keeps learning alive, layer norm by hand, and add and norm.40 min
115A transformer block, start to finishFreeA sentence through embeddings, attention, add and norm, a small network and next-word scores, every shape named.45 min
117Final test: transpose any formulaFreeSlips to fix from every topic, mixed practice of every kind of rearranging, the strategy chart and the full sheet.45 min
Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.
See the course →
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write