python题目:维度为(M,N)求矩阵的转置【杭州多测师】【杭州多测师_王sir】

import numpy

def func1(m):
    '''转置的第一种方法'''
    return numpy.transpose(m).tolist()

print(numpy.matrix([[1, 2, 3],[4 ,5, 6],[7, 8,9]]))         #转置之前的数据
print(numpy.matrix(func1([[1, 2, 3],[4 ,5, 6],[7, 8,9]])))  #转置之后的数据


def func2():
    '''转置的第二种方法'''
    a = numpy.array([[1, 2, 3],[4 ,5, 6],[7, 8,9]])
    print(a)       #转置之前的数据
    print(a.T)     #转置之后的数据

func2()
原文地址:https://www.cnblogs.com/xiaoshubass/p/14638509.html