Skip to main content

Module 4 · before

Math toolkit (visual first)

6 questions on what this module teaches. Guessing is fine: this is your starting point, not a test. Take the same check again at the end to see what you learned.

1. What does this print?
def f(x):
    return (x - 2) * (x - 2) + 1

best = min([(f(x), x) for x in range(-3, 6)])
print(best)
2. A learner writes the slope as return f(x + h) - f(x - h) / (2 * h). Why are the answers wrong?
3. What does this print?
import math
p = 0.5 * 0.5 * 0.5
print(round(-math.log(p), 2), round(3 * -math.log(0.5), 2))
4. What does this print?
def dot(a, b):
    total = 0
    for x, y in zip(a, b):
        total += x * y
    return total

def linear(x, w):
    return [dot(wo, x) for wo in w]

print(linear([2, -1], [[1, 1], [0, 3], [-2, 0]]))
5. What does this print?
counts = {'a': 2, 'b': 1, 'c': 1}
total = sum(counts.values())
chances = {}
for k in counts:
    chances[k] = counts[k] / total
print(chances['a'], sum(chances.values()))
6. w is a matrix with 10 rows of 4 numbers. For linear(x, w) to work, how long must x be, and how many numbers come out?

Your answers are saved with a random id, not your name, so we can see which lessons work. Privacy