Skip to content

Instantly share code, notes, and snippets.

View LeJit's full-sized avatar

Manojit Nandi LeJit

View GitHub Profile
@LeJit
LeJit / plotComplex
Last active August 29, 2015 14:05
A Python Script to plot a sequence of complex points and the corresponding derivatives for each point.
def plotComplexPointsAndVectors(locations, derivatives):
X,Y = zip(*map(lambda x: (x.real, x.imag), locations))
U,V = zip(*map(lambda x: (x.real, x.imag), derivatives))
plt.plot(X,Y, "ro-", label="python")
limit = np.max(np.ceil(np.absolute(points)))
plt.xlim((-limit, limit))
plt.ylim((-limit, limit))
plt.xlabel("Real")
plt.ylabel("Imaginary")
plt.quiver(X,Y,U,V, linewidths = 2)
@LeJit
LeJit / recommenderSystem.py
Created March 21, 2014 00:31
A simple movie recommendation system in Python
from math import pow, sqrt
def cosine(ratings1, ratings2):
norm1 = sum([pow(rating,2) for rating in ratings1.values()])
norm2 = sum([pow(rating,2) for rating in ratings2.values()])
intersect_keys = filter(lambda x: x in ratings1.keys(), ratings2.keys())
dot_product = sum([ratings1[key]*ratings2[key] for key in intersect_keys])
cosine_distance = dot_product/(sqrt(norm1*norm2))
return cosine_distance