python - Problems with Matrix Multiplication -


i'm having troubles when comes multiplying 2 matrices. attributeerror appears when i'm trying perform 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 new matrix in instance called example m3 thought better use self instead.

here's code:

def multiplymatrices(self,m1,m2):     if m1.getrows() == m2.getcolumns() , m1.getcolumns() == m2.getrows():         self.setrows()         self.setcolumns()         in range(m1.getrows()):             j in range(m2.getcolumns()):                 k in range(m1.getcolumns()):                     self[i][j] += (m1[i][k])*(m2[k][j]) 

i created instance of self in main(), before calling multiplymatrices()

according attributeerror, never defined __getitem__ method in class. this how can control object[key] access. suggest reading on python data model in general if deciding make more advanced class (like one) in python. although bit strange have multiplication of 2 other matrices being stored in self. i'd create new matrix in method , return that.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -