Skip to content

Instantly share code, notes, and snippets.

@captbaritone
Created August 5, 2015 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save captbaritone/851ee3a0896ad90d242f to your computer and use it in GitHub Desktop.
Save captbaritone/851ee3a0896ad90d242f to your computer and use it in GitHub Desktop.
from numpy.linalg import svd
from numpy import array
CLUSTERS = 2
character_index_lookup = {
0: "Papageno",
1: "Figaro",
2: "Mimi",
3: "Rudolfo",
4: "Susanna"
}
# Singer resumes
# Rows represent signers, columns represent characters
singer_matrix = array([
(1, 1, 0, 0, 0),
(1, 1, 0, 0, 0),
(0, 0, 1, 0, 1),
(0, 0, 0, 1, 0),
])
# Do magic with maths
U, s, V = svd(singer_matrix)
clusters = V[:CLUSTERS]
# Each column represents a character
input_singer_vector = array([1, 0, 0, 0, 0])
singer_fach = input_singer_vector.dot(clusters.transpose()).dot(clusters)
for index, score in enumerate(singer_fach):
if score > 0:
print character_index_lookup[index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment