Commit 480ddd5c authored by SHRADDHEYA SHENDRE's avatar SHRADDHEYA SHENDRE

Adding task3.py (B3)

parent 2f8c3463
f = open('matrix.txt', 'r')
line1 = f.readline()
rowscols = line1.split()
rows = int(rowscols[0])
cols = int(rowscols[1])
Mat = [[None for j in range(cols)] for i in range(rows)]
for i in range(rows):
line = f.readline()
colvec = line.split()
for j in range(cols):
Mat[i][j] = colvec[j]
f.close()
Trans = [[None for j in range(rows)] for i in range(cols)]
for i in range(cols):
for j in range(rows):
Trans[i][j] = Mat[j][i]
f2 = open('transpose.txt','w')
f2.write(str(cols))
f2.write(" ")
f2.write(str(rows))
f2.write("\n")
for i in range(cols):
for j in range(rows):
f2.write(str(Trans[i][j]))
f2.write(" ")
f2.write("\n")
f2.close()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment