Skip to content

Commit 8a02f3d

Browse files
committed
fixed the code in matrix multiplication in docs/datastructure.rst line number: 442
changed the output of matrix multiplication example in docs/datastructure.rst
1 parent abaf356 commit 8a02f3d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/datastructure.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ In this example we will multiply two matrices. First we will take input the numb
439439
b.append([int(x) for x in input("").split(" ")])
440440
c = []
441441
for i in range(0, n):
442-
c.append([a[i][j] * b[j][i] for j in range(0, n)])
442+
c.append([ sum([a[i][k] * b[k][j] for k in range(0, n)]) for j in range(0,n) ])
443443
print("After matrix multiplication")
444444
print("-" * 10 * n)
445445
for x in c:
@@ -464,9 +464,9 @@ The output
464464
3 2 1
465465
After matrix multiplication
466466
------------------------------
467-
9 12 9
468-
32 25 12
469-
49 32 9
467+
30 24 18
468+
84 69 54
469+
138 114 90
470470
------------------------------
471471

472472
Here we have used list comprehensions couple of times. *[int(x) for x in input("").split(" ")]* here first it takes the input as string by *input()*, then split the result by " ", then for each value create one int. We are also using *[a[i][j] * b[j][i] for j in range(0,n)]* to get the resultant row in a single line.

0 commit comments

Comments
 (0)