Commit b5384dd3 authored by ARCHIT GUPTA's avatar ARCHIT GUPTA

added part 3

parent ff8b9eac
#open the file in read mode
fo = open("matrix.txt", "r")
#initialsing a list for reading file
mat = []
for line in open('matrix.txt').readlines():
mat.append(map(int,line.split()))
#no of rows and columns
row=mat[0][0]
col=mat[0][1]
#initialising a 2D array for storing matrix
matrix=[]
#initialising with correct size
matrix=[[0 for i in range(row)] for j in range(col)]
matrix=[[mat[j+1][i] for i in range(col)] for j in range(row)]
#transpose matrix
matrix2=[[mat[i+1][j] for i in range(row)] for j in range(col)]
#writing in file
foo=open('transpose.txt','w')
foo.write(str(col))
foo.write(' ')
foo.write(str(row))
foo.write('\n')
for i in range(row):
for j in range(col):
foo.write(str(matrix2[i][j]))
foo.write(' ')
foo.write('\n')
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