By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,516 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,516 IT Pros & Developers. It's quick & easy.

multiply two matrices

P: 20
Expand|Select|Wrap|Line Numbers
  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
  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
  23. def display(list):
  24.     for r in list:
  25.         for c in r:
  26.             print c,
  27.         print''
  29. print 'enter A'
  30. matA=readmat(3,4)
  31. print 'enter B'
  32. matB=readmat(4,3)
  33. display(product())
why it say that list index out of bound???there is an error in product(),can u please help me?
May 9 '14 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 2.5K+
P: 2,851
Please don't use Python builtin types for identifiers such as str and list.

You received the error because you have a list of lists (matA) and each element is only one element long, I think. I can't be sure what you expect to enter into the raw_input widget.
May 9 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.