输入
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
预期产量
[[20, 1], [20, 7], [1, 9]]
[(0, 0), (1, 0)]
预先感谢
答案 0 :(得分:0)
这在这里应该起作用:
matrix = [[20, 1], [20, 7], [1, 9]]
max_n = matrix[0][0]
result = []
for row in range(len(matrix)):
for col in range(len(matrix[0])):
if matrix[row][col] == max_n:
result.append((row, col))
elif matrix[row][col] > max_n:
max_n = matrix[row][col]
result = [(row, col)]
print(result)
答案 1 :(得分:0)
这可能不是最有效的解决方案,但会有所帮助
matrix = [[20, 1], [20, 7], [1, 9]]
xIndex = []
yIndex = []
maxValues = []
cord = []
finalCord = []
finalMaxIndex = []
for i in range(len(matrix)):
xIndex.append(i)
maxSublist = max(matrix[i])
yIndex.append(matrix[i].index(maxSublist))
for i, j in zip(xIndex, yIndex):
cord.append((i,j))
maxValues.append(matrix[i][j])
maxValue = max(maxValues)
for i in range(len(maxValues)):
if maxValue == maxValues[i]:
finalMaxIndex.append(i)
else:
pass
for i in finalMaxIndex:
finalCord.append(cord[i])
print('Index of multiple greatest elements in nested list or matrix:', finalCord)
矩阵= [[20,1],[20,7],[1,9]] 输出= [(0,0),(1,0)]
答案 2 :(得分:0)
首先找到列表列表的最大值,然后使用列表理解找到值等于最大值的元素的位置
>>> lst = [[20, 1], [20, 7], [1, 9]]
>>> m = max(e for sub_lst in lst for e in sub_lst)
>>> [(i, j) for i,sub_lst in enumerate(lst) for j,e in enumerate(sub_lst) if e==m]
[(0, 0), (1, 0)]