Created
August 27, 2014 15:22
-
-
Save felixlaumon/42e98ffeb1fd940a53da to your computer and use it in GitHub Desktop.
matrix * vector without using itertool and mul
This file contains 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ha! I suppose this gets my vote for most elegant solution. Well done!