我在列表的以下列表(60行x 6列)中存儲了60個交貨點和6個接收點之間的距離。每個列索引都是接收點的ID。每行索引是傳遞點的ID,每行中的值包含接收點和傳遞點之間的距離值。我希望輸出是列表的列表,第一個列表應該用于第一個接收點,其中包含離它最近的傳遞點(即行索引)的ID(即具有最小距離的傳遞點)。如果接收點的ID超過10個,則第二個接收點應采用傳遞點的索引。[[8.8571112536429428, 8.9401324296172984, 11.610640135587387, 13.695908399729435, 14.239701934343463, 16.347271804009676], [9.1542700414794123, 9.301375660862357, 12.042023807282666, 14.278330930177338, 14.822147396293593, 16.926281570649053], [9.3549480280083053, 9.4363340620527882, 12.0922348611257, 13.959594685254489, 14.499353590653021, 16.657032572800848], [9.6487557392404799, 9.7657869305623226, 12.460747138875766, 14.374363831842004, 14.913246132168481, 17.078816216816612], [9.8500830619048756, 9.941928195489762, 12.600424422369565, 14.320647726487726, 14.856529889513659, 17.053401733435681], [10.208637100585225, 10.207676145898613, 12.723522650837346, 13.856177303497407, 14.382791865423997, 16.658587307014372], [10.1910872674719, 10.037355180092288, 12.283344476416266, 12.66725004132222, 13.183857132732589, 15.526690228503712], 我的代碼如下所示無法正常工作:def GetDistance(i,k): distance = 4.1*(i**2) - 6.2*(k**2) return distance def my_min(sequence): low = sequence[0] for i in sequence: if i < low: low = i return sequence.index(low)list = []listOflist = []numberOfrows = 60numberOfcolumns = 6for i in range(numberOfrows): for k in range(numberOfcolumns): distance = GetDistance(i,k) ## get the distance value from another function list.append(distance) columnIndex = my_min(list[numberOfcolumns*i:(i+1)*numberOfcolumns]) columnIndices.append(columnIndex)所需的結果如下所示:listOflist = [[rowId,rowId,rowId,rowId,rowId,rowId,rowId,rowId,rowId,rowId] # This is the list of the first column index and the values inside are the row indices with top 10 minimum values ,[3,14,42,35,53,27,19,0,34,22,7] # second column index with the row indices of the top 10 values,... 非常感謝您的幫助。
查看完整描述