将两个矩阵相乘

巨蟒

选择 | 换行 | 行号
  1. def readmat(r,c):
  2.     for i in range(r):
  3.         list=[]
  4.         str=raw_input()
  5.         templist=str.split()
  6.         raw=map(int,templist)
  7.         list.append(raw)
  8.     return list
  9.  
  10. def product():
  11.     list=[]
  12.     for i in matA:
  13.         sublist=[]
  14.         print i[3],matB[1][1]
  15.         for x in range(3):
  16.             sum=0
  17.             for e in range(4):
  18.                 sum+=i[e]*matB[e][x]
  19.             sublist.append(sum)
  20.         list.append(sublist)
  21.     return list
  22.  
  23. def display(list):
  24.     for r in list:
  25.         for c in r:
  26.             print c,
  27.         print''
  28.  
  29. print 'enter A'
  30. matA=readmat(3,4)
  31. print 'enter B'
  32. matB=readmat(4,3)
  33. display(product())
  34.  
  35.  

为什么说列表索引越界?product()中有错误,能帮帮我吗?

# 回答1


请不要将Python内置类型用于标识符如
应力

列表

您收到这个错误是因为您有一个列表列表(Mata),并且我认为每个元素只有一个元素长。我不确定您希望在RAW_INPUT小部件中输入什么内容。

标签: python

添加新评论