Skip to content

Instantly share code, notes, and snippets.

@felixlaumon
Created August 27, 2014 15:22
Show Gist options
  • Save felixlaumon/42e98ffeb1fd940a53da to your computer and use it in GitHub Desktop.
Save felixlaumon/42e98ffeb1fd940a53da to your computer and use it in GitHub Desktop.
matrix * vector without using itertool and mul
matrix = [
[1,3,9,2],
[2,4,6,8]
]
vector = [2,3,6,5]
def dot_product (a, b):
return sum(map(lambda x: x[0] * x[1], zip(a, b)))
def mv_multiple (matrix, vector):
return [dot_product(row, vector) for row in matrix]
print mv_multiple(matrix, vector)
@tijptjik
Copy link

Ha! I suppose this gets my vote for most elegant solution. Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment