這是我的代碼:爲什麼我總是得到錯誤「list」對象沒有屬性'tranpose'?
class Matrix(object):
"""List of lists, where the lists are the rows of the matrix"""
def __init__ (self, m=3,n=3,ma=[[1,2,3],[4,5,6], [7,8,9]]):
self.n_rows=m
self.n_cols=n
self.matrix=ma=list(ma)
def __repr__(self):
"""String representation of a Matrix"""
output= "Matrix: \n{} \n Your matrix has \n {} columns \n {} rows"\
.format(self.matrix, self.n_cols, self.n_rows)
return output
def transpose (self):
"""Transpose the Matrix: Make rows into columns and columns into rows"""
ma_transpose=[]
for r in zip(*self.matrix):
ma_transpose.append(list(r))
return ma_transpose
def matrixmult (self,other):
"""Matrix Multiplication of 2 Matrices"""
m2=other.matrix
ma2_t=m2.transpose()
table=[]
for r in self.matrix:
row=[]
for n in ma2_t:
row.append(dot_mult(r,n))
table.append(row) into a list of row
res=table
return res
但每次我嘗試使用matrixmult
功能的時候,我總是得到「的列表對象有沒有屬性matrixmult」。這是爲什麼?我之前在代碼中定義了它?
ma2_t=m2.transpose()
AttributeError的: '名單' 對象沒有屬性 '轉'
有人請幫助?
看看'res'。它是什麼類型? – user2357112