Lissa Hopson
2015-07-29 09:16:58 UTC
I'm taking a beginning Python course at Austin Community College. I'm also
taking two other project-based web programming courses. It's summer
semester, meaning we have eight weeks instead of the usual 16 to finish all
the requirements.
The semester ends Friday, July 131st.
Yes, I am aware that I'm a teensy bit screwed.
I have to complete eight programs ("complete" meaning "functioning"). I'm
having a really tough time with this one. It's matrix arithmetic using 2d
arrays.
If ANYONE can help me, I'd really appreciate it. Someday, maybe I can be
the guy helping someone else...except I'm a girl. Whatever. I digress. I'm
already planning to retake the course because I want to get more out of it-
I like Python a lot, it's just really difficult to absorb it all that
fast...especially since I'm used to HTML and JavaScript.
Okay- so these are the directions for the program, and I'll cut and paste
my program so far from the interpreter to the email. Don't want to freak
anyone out with attachments. It's gonna be a long email.
Given x as an array of [5,3] and y as an array of [3,7] perform the
following:
1. Load array x column-wise and array y row-wise
2. Multiply x by y to compute array z
3. Compute the sum of all elements in column 2 of array x and add it to the
sum of all elements in row 2 of y (the first row/column is 0, the second is
1, etc. That got me at first)
4. Compute the smallest element in row 1 of y
---using appropriate headings:
5. Print out matrices x, y, and z (display on screen, but y'all probably
get that)
6. Print out sum and smallest element
The data with which array x is loaded:
1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 0, 1, 2, 3, 4
The data with which array y is loaded:
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 0, 1
Must use functions named as follows:
LOADX, LOADY, COMPUTEZ, SMALLEST, SUMMATION, OUTDATA
lab5.dat is simply a dat file with the data with which the arrays are
loaded in one long line, each separated by commas.
Thanks- in advance- no more comments after the program.
This is what I have thus far:
#Lab #5
#COSC 1336-31493
#SUM 2015 NRG
#Tu/Th 1:15-4:25pm
def main():
#matrix initialization
x=[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
y=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
z=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
#file declaration
infile = open('lab5x.dat','r')
infile = open('lab5y.dat','r')
outfile = open('lab5.out', 'w')
#variables
sumx = 0
sumy = 0
small = 0
A = 0
B = 0
C = 0
#call functions
LOADX(infile, A)
LOADY(infile, B)
COMPUTEZ(A, B, C)
SUMMATION(A, B)
SMALLEST(A)
OUTDATA(file, A, B, C)
#close files
infile.close()
infile.close()
outfile.close()
dummy = input('Press any key to continue.')
#develop functions
#load matrix x
def LOADX(infile, A):
#local variables
n=0
k=0
s=0
templist = infile.readline().strip('\n').split(',')
while (k<3):
j=0
while(j<5):
A[j][k] = int(templist[n])
s=s+A[j][k]
j=j+1
k=k+1
n=n+1
#load matrix y
def LOADY(infile, B):
#local variables
n=0
j=0
templist = infile.readline().strip('\n').split(',')
while (j<3):
k=0
while (k<7):
B[j][k] = int(templist[n])
s=s+B[j][k]
j=j+1
n=n+1
k=k+1
#define computation of Z matrix
def COMPUTEZ (A, B, C):
i=0
while (i<5):
j=0
while (j<=7):
k=0
while (k<=3):
C[i][j]= C[i][j]+ A[i][k] * B[k][j]
k=k+1
j=j+1
i=i+1
#def summation
def SUMMATION(x,y):
s=0
k=0
j=0
while (k<5):
sumx=sumx + x[k][2]
k=k+1
while (j<7):
sumy=sumy + y[2][j]
j=j+1
s=sumx + sumy
#def smallest
def SMALLEST (B):
k=0
s=B[1][k]
k=k+1
while (k<7):
if(s> B[1][k]):
s=B[1][k]
k=k+1
def OUTDATA(outfile, x, y, z,SMALLEST,SUMMATION):
i=0
j=0
k=0
while (k<3):
print(A[k][0],A[k][1],A[k][2],A[k][3],A[k][4])
k=k+1
file.write[str(A[k][0])+str(A[k][1])+str(A[k][2])+str(A[k][3])+str(A[k][3])+str(A[k][4])]
while (j<7):
print(B[j][0],B[j][1],B[j][2])
j=j+1
file.write[str(B[j][0])+str(B[j][1])+str(B[j][2])]
while (i<7):
print(C[i][0],C[i][1],C[i][2],C[i][3],C[i][4])
file.write[str(C[i][0]+C[i][1]+C[i][2]+C[i][3]+C[i][4])]
print ('Summation= ',SUMMATION)
file.write('Summation= ', SUMMATION)
print ('Smallest= ',SMALLEST)
file.write('Smallest= ',SMALLEST)
main()
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
taking two other project-based web programming courses. It's summer
semester, meaning we have eight weeks instead of the usual 16 to finish all
the requirements.
The semester ends Friday, July 131st.
Yes, I am aware that I'm a teensy bit screwed.
I have to complete eight programs ("complete" meaning "functioning"). I'm
having a really tough time with this one. It's matrix arithmetic using 2d
arrays.
If ANYONE can help me, I'd really appreciate it. Someday, maybe I can be
the guy helping someone else...except I'm a girl. Whatever. I digress. I'm
already planning to retake the course because I want to get more out of it-
I like Python a lot, it's just really difficult to absorb it all that
fast...especially since I'm used to HTML and JavaScript.
Okay- so these are the directions for the program, and I'll cut and paste
my program so far from the interpreter to the email. Don't want to freak
anyone out with attachments. It's gonna be a long email.
Given x as an array of [5,3] and y as an array of [3,7] perform the
following:
1. Load array x column-wise and array y row-wise
2. Multiply x by y to compute array z
3. Compute the sum of all elements in column 2 of array x and add it to the
sum of all elements in row 2 of y (the first row/column is 0, the second is
1, etc. That got me at first)
4. Compute the smallest element in row 1 of y
---using appropriate headings:
5. Print out matrices x, y, and z (display on screen, but y'all probably
get that)
6. Print out sum and smallest element
The data with which array x is loaded:
1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 0, 1, 2, 3, 4
The data with which array y is loaded:
2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 3, 5, 7, 9, 0, 2, 4, 6, 8, 0, 1
Must use functions named as follows:
LOADX, LOADY, COMPUTEZ, SMALLEST, SUMMATION, OUTDATA
lab5.dat is simply a dat file with the data with which the arrays are
loaded in one long line, each separated by commas.
Thanks- in advance- no more comments after the program.
This is what I have thus far:
#Lab #5
#COSC 1336-31493
#SUM 2015 NRG
#Tu/Th 1:15-4:25pm
def main():
#matrix initialization
x=[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
y=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
z=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
#file declaration
infile = open('lab5x.dat','r')
infile = open('lab5y.dat','r')
outfile = open('lab5.out', 'w')
#variables
sumx = 0
sumy = 0
small = 0
A = 0
B = 0
C = 0
#call functions
LOADX(infile, A)
LOADY(infile, B)
COMPUTEZ(A, B, C)
SUMMATION(A, B)
SMALLEST(A)
OUTDATA(file, A, B, C)
#close files
infile.close()
infile.close()
outfile.close()
dummy = input('Press any key to continue.')
#develop functions
#load matrix x
def LOADX(infile, A):
#local variables
n=0
k=0
s=0
templist = infile.readline().strip('\n').split(',')
while (k<3):
j=0
while(j<5):
A[j][k] = int(templist[n])
s=s+A[j][k]
j=j+1
k=k+1
n=n+1
#load matrix y
def LOADY(infile, B):
#local variables
n=0
j=0
templist = infile.readline().strip('\n').split(',')
while (j<3):
k=0
while (k<7):
B[j][k] = int(templist[n])
s=s+B[j][k]
j=j+1
n=n+1
k=k+1
#define computation of Z matrix
def COMPUTEZ (A, B, C):
i=0
while (i<5):
j=0
while (j<=7):
k=0
while (k<=3):
C[i][j]= C[i][j]+ A[i][k] * B[k][j]
k=k+1
j=j+1
i=i+1
#def summation
def SUMMATION(x,y):
s=0
k=0
j=0
while (k<5):
sumx=sumx + x[k][2]
k=k+1
while (j<7):
sumy=sumy + y[2][j]
j=j+1
s=sumx + sumy
#def smallest
def SMALLEST (B):
k=0
s=B[1][k]
k=k+1
while (k<7):
if(s> B[1][k]):
s=B[1][k]
k=k+1
def OUTDATA(outfile, x, y, z,SMALLEST,SUMMATION):
i=0
j=0
k=0
while (k<3):
print(A[k][0],A[k][1],A[k][2],A[k][3],A[k][4])
k=k+1
file.write[str(A[k][0])+str(A[k][1])+str(A[k][2])+str(A[k][3])+str(A[k][3])+str(A[k][4])]
while (j<7):
print(B[j][0],B[j][1],B[j][2])
j=j+1
file.write[str(B[j][0])+str(B[j][1])+str(B[j][2])]
while (i<7):
print(C[i][0],C[i][1],C[i][2],C[i][3],C[i][4])
file.write[str(C[i][0]+C[i][1]+C[i][2]+C[i][3]+C[i][4])]
print ('Summation= ',SUMMATION)
file.write('Summation= ', SUMMATION)
print ('Smallest= ',SMALLEST)
file.write('Smallest= ',SMALLEST)
main()
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor