← Lesson
Linear Maps
Joeven
Run
Reset
Python loads on first run
import math def mat_vec(W, x): return [sum(a * b for a, b in zip(row, x)) for row in W] def scale_xy(sx, sy): return [[sx, 0.0], [0.0, sy]] def rotation(t): c, s = math.cos(t), math.sin(t) return [[c, -s], [s, c]] p = [1.0, 0.0] print("point", p) print("scale 2,2", mat_vec(scale_xy(2, 2), p)) print("stretch x*3", mat_vec(scale_xy(3, 1), p)) R = rotation(math.pi / 2) out = mat_vec(R, p) print("rotate 90", [round(out[0], 6), round(out[1], 6)]) doc = [0.6, 0.8] W = scale_xy(0.1, 10.0) print("raw doc", doc, "query", p) print("stretched doc", mat_vec(W, doc), "stretched query", mat_vec(W, p))
Run to execute this in your browser. Nothing is sent to a server.