473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiply two matrices

20 New Member
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 2197
bvdet
2,851 Recognized Expert Moderator Specialist
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
13249
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 matricies at compile-time? Any help would be appreciated. Hopefully this code comes in useful for someone, let me know if you find it useful, or if...
1
1623
by: salaam2indya | last post by:
Use pointer to multiply two matrices.
13
1572
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
2379
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 equal to the product of and the current vector {x} + constant vector {z}. Perform the matrix multiplication by using the function:
3
6095
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 follows #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> void printArray( const int a,int row, int column); /*...
1
4297
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 multiplication. Computes matrix1 * matrix2 and stores the
0
1305
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 two matrices shall be multiplied using matrix multiplication and when the elements of these matrices are multiplied, this shall be done elementwise....
1
2064
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> #include<pthread.h> int mata; int matb; int matc;
0
7715
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.