Skip to content

Commit add2f89

Browse files
authored
Easy and Simple Solution
1 parent 41bdea8 commit add2f89

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)