Skip to content

Commit

Permalink
fixed the code in matrix multiplication in docs/datastructure.rst lin…
Browse files Browse the repository at this point in the history
…e number: 442

changed the output of matrix multiplication example in docs/datastructure.rst
  • Loading branch information
RaviTejaKomma committed Jul 25, 2018
1 parent abaf356 commit 8a02f3d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/datastructure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ In this example we will multiply two matrices. First we will take input the numb
b.append([int(x) for x in input("").split(" ")])
c = []
for i in range(0, n):
c.append([a[i][j] * b[j][i] for j in range(0, n)])
c.append([ sum([a[i][k] * b[k][j] for k in range(0, n)]) for j in range(0,n) ])
print("After matrix multiplication")
print("-" * 10 * n)
for x in c:
Expand All @@ -464,9 +464,9 @@ The output
3 2 1
After matrix multiplication
------------------------------
9 12 9
32 25 12
49 32 9
30 24 18
84 69 54
138 114 90
------------------------------

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.
Expand Down

0 comments on commit 8a02f3d

Please sign in to comment.