我在列表的以下列表(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,... 非常感谢您的帮助。
查看完整描述