Answer to Question #17465 in Python for Axelle Jamous

Question #17465
So I need to create a class Matrix for school.
It was going pretty well until I had to create the function sum. (highlighted)

def sum(self, other_matrix):
summx = Matrix(self.m, self.n)

for rw in range(self.m):
row = [sum(el) for el in zip(self.mx[rw], other_matrix[rw])]
summx[rw] = row
return temp

I searched for hours and hours to find a solution, tried different approaches. Some people even use the same code as I do, so I'm definitely doing something wrong. The only thing I can't seem to figure out is what.

I keep getting the error:

Traceback (most recent call last):
File "testmatrix.py", line 33, in <module>
j = g.sum(i)
File "/home/axelle/matrix.py", line 45, in sum
row = [sum(el) for el in zip(self.mx[rw], other_matrix[rw])]
TypeError: 'Matrix' object does not support indexing

Please help, I'm kinda desperate ^.^
Thanks in advance.
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS