Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Matrix Multiplication in Python
40 points
Due Date/Time:
The program is due on Monday, October 19th at 11:59 pm on edoras. The name of your program must be
p3.py
The Program:
For this assignment, you will multiply two matrices and print the result. If A is an m x n matrix, and B is
an n x p matrix, then the product matrix C, which is A x B, is defined to be the m x p matrix whose entry in
the ith row and the jth column is the sum of the products of corresponding entries of the ith row of A and the
j
th column of B. A standard algorithm is:
for(int i=0; i < m; i++)
for(int j=0; j < p; j++) {
C[i][j] = 0;
for(int k=0; k < n; k++)
C[i][j] += A[i][k] * B[k][j];
}
Input:
will take the following form. The first three lines of the file contain the values m, n, and p, each on a line
by themselves. Following are two matrices, A followed by B with no blank lines, of the dimensions
specified, one row per line. Each row entry is separated by a space. Example: Given the following two
matrices A and B:
A = |1 2| B = |3|
|4|
The datafile will then have this format:
sys library:
For this assignment, the only library you may is sys. (Python has a built-in array module, which you may
not use. Instead, the matrices will be lists which are very similar to arrays.) Immediately following the
header comment section at the top of your program, add the line:
import sys
Output:
As usual, your program will first print a title line, consisting of the assignment number, your class account,
and your name, all on one line. Then your program will print the two matrices to be multiplied, and finally
print the resulting matrix (pretty formatting is appreciated, but not necessary). Each of the three matrices
should be labeled. Example:
Program #3, csscxxxx, Student Name
Matrix A contents:
Matrix B contents:
7 8 9 10
11 12 13 14
Matrix A * B is:
29 32 35 38
65 72 79 86
101 112 123 134
The datafile read for this example is:
Additional Requirements:
? You may use brackets [ ] in your code.
? The matrices A and B must be declared as empty lists: A = [] and B = []
? No error checking of input data file content is required for this assignment. You may assume that any
datafile used for testing will contain only integer values in the format specified in the assignment.