473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

multiply two matrices

python
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
  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.  
why it say that list index out of bound???there is an error in product(),can u please help me?
May 9 '14 #1
1 2191
bvdet
2,851 Expert Mod 2GB
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

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

Similar topics

15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
1
by: salaam2indya | last post by:
Use pointer to multiply two matrices.
13
by: luvuyo | last post by:
hai everyone, i would like someone to help me with a c++ program that adds, subtracts and multiply matrices
0
by: arperidot | last post by:
Develop a program which computes the current value of the vector {x} based on the following forward iteration: {x}(n+1) = {x}(n)+ {z}, n = 0,1,2,3,4. In other words, the next vector {x} is...
3
by: David Barnwell | last post by:
Im trying to multiply a 5X5 matrix filled with random numbers with another matrix, also filled with random numbers. I'm still trying to fill the two matrices and then display them my code is as...
1
by: siggy key | last post by:
I have the following definition typedef struct matrix_t { int rows, columns; Complex** nextElement;// TODO: Add fields }*Matrix; and I have to implement /** * Performs matrix...
0
by: Petan Kl | last post by:
Hello, I am wondering if there is an efficient way (other than for cycle) of solving following task: I need to multiply e.g. two matrices and at every point in the matrix there is an array. The...
1
by: Chris S | last post by:
In my main program i am filling 2 matrices mata and matb. Then I'm multiplying them in my thread function to get matc. However, i am getting segmentation falults #include<stdio.h>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.