We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41bdea8 commit add2f89Copy full SHA for add2f89
Problems/1_matrix_times_vector/Easy_and_simple_solution.py
@@ -0,0 +1,13 @@
1
+def matrix_dot_vector(a: list[list[int|float]], b: list[int|float]) -> list[int|float]:
2
+ # if the no. of columns of a is not equal to the len of vector b then return -1
3
+ if len(a[0]) != len(b):
4
+ return -1
5
+ # create a vector to store the values
6
+ result = []
7
+ # traverse through the matrix and add do the dot product and append to the result vector
8
+ for i in range(len(a)):
9
+ val = 0
10
+ for j in range(len(b)):
11
+ val += a[i][j] * b[j]
12
+ result.append(val)
13
+ return result
0 commit comments