I'm having some troubles when it comes to multiplying two matrices. An AttributeError appears when I'm trying to perform the addition part
Traceback (most recent call last): File "MatrixClass.py", line 189, in <module> main() File "MatrixClass.py", line 184, in main mat.multiplyMatrixes(mat1,mat2) File "MatrixClass.py", line 176, in multiplyMatrixes self[i][j] += (m1[i][k])*(m2[k][j]) AttributeError: matrix instance has no attribute '__getitem__' I tried saving the new matrix in another instance called for example m3 but the I thought it would be better to use self instead.
Here's my code:
def multiplyMatrices(self,m1,m2): if m1.getRows() == m2.getColumns() and m1.getColumns() == m2.getRows(): self.setRows() self.setColumns() for i in range(m1.getRows()): for j in range(m2.getColumns()): for k in range(m1.getColumns()): self[i][j] += (m1[i][k])*(m2[k][j]) I created the instance of self in main(), before calling multiplyMatrices()
__getitem__method?__getitem__method? (If you did, is it still there when you look for it? And is the name right?)m0.multiplyMatrices(m1, m2)is going to end up replacing the contents ofm0withm1 * m2Why would you want that? Can you show us (a stripped-down version of) your class definition, and describe what the API is supposed to be?@propertys