Matrix Transpose in Python

前端 未结 18 1209
甜味超标
甜味超标 2020-11-22 00:21

I am trying to create a matrix transpose function for python but I can\'t seem to make it work. Say I have

theArray = [[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\         


        
18条回答
  •  既然无缘
    2020-11-22 00:59

    a=[]
    def showmatrix (a,m,n):
        for i in range (m):
            for j in range (n):
                k=int(input("enter the number")
                a.append(k)      
    print (a[i][j]),
    
    print('\t')
    
    
    def showtranspose(a,m,n):
        for j in range(n):
            for i in range(m):
                print(a[i][j]),
            print('\t')
    
    a=((89,45,50),(130,120,40),(69,79,57),(78,4,8))
    print("given matrix of order 4x3 is :")
    showmatrix(a,4,3)
    
    
    print("Transpose matrix is:")
    showtranspose(a,4,3)
    

提交回复
热议问题