Last active
December 20, 2015 05:49
-
-
Save vadimii/6081620 to your computer and use it in GitHub Desktop.
Convex combination for Coursera's "Coding the Matrix" course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from vec import Vec | |
from plotting import plot | |
def list2vec(l): | |
D = set(range(len(l))) | |
return Vec(D, {k: v for k, v in enumerate(l)}) | |
def draw_line(p1, p2): | |
resolution = 10 | |
alphas = (float(i)/resolution for i in range(resolution+1)) | |
scalers = ((alpha, 1-alpha) for alpha in alphas) | |
points = (alpha*p1+beta*p2 for alpha, beta in scalers) | |
points = [list(x.f.values()) for x in points] | |
plot(points, 5) | |
time.sleep(10) | |
u = list2vec([2, 1]) | |
v = list2vec([-2, 2]) | |
draw_line(u, v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment