矩阵的行列表示

在对一个矩阵进行遍历操作及更进一步的算法设计时往往会用到行、列表示。
如矩阵matrix:

class solution():   
    def printMatrix(self, matrix):
        rows = len(matrix)
        columns = len(matrix[0])
        print(rows,columns)
if __name__=='__main__':
    matrix = [[1,  2,  3],
              [5,  6,  7],
              [9, 10, 11],
              [13, 14, 15]]
    s=solution()
    s.printMatrix(matrix)
rows =4
columns =3

猜你喜欢

转载自blog.csdn.net/zztingfeng/article/details/80546822