拉丁的传说
def GetRowAndColum(iNoOfRows, iNoOfColumn, iIndex): #Floor division to get row iRowInMatrix = iIndex//iNoOfColumn iColumnInMatrix = iIndex % iNoOfColumn return iRowInMatrix, iColumnInMatrixmat = ['a', 'b', 'c', 'd', 'e', 'f']iNoOfColumn = 2iNoOfRows = 3iIndex = 5i, j = GetRowAndColum(iNoOfRows, iNoOfColumn, iIndex)print "Row in matrix: ", iprint "Column in matrix: ", j输出:[试用]$ python TestMat.py 矩阵中的行:2 矩阵中的列:1我假设矩阵具有从零开始的索引。如果您的索引以 1 开头,则只需将 1 添加到行和列索引。