我们这样说:
atable = [[6, 2, 3, 1], [3, 4, 2, 1], [4, 8, 7, 6], [8, 9, 3, 7]]
不使用numpy或flattened,如何找到整个列表的最小值?
我认为您可以使用列表,但不确定。
答案 0 :(得分:2)
以下是几种方法:
from itertools import chain
atable = [[6, 2, 3, 1], [3, 4, 2, 1], [4, 8, 7, 6], [8, 9, 3, 7]]
# Flatten the sublists into a single list
result = min(chain.from_iterable(atable))
# Find the min of each list, the find the min of mins
result = min(map(min, atable))
# Use a generator expression with nested loops
result = min(i for lst in atable for i in lst)
答案 1 :(得分:0)
这是一种蛮力方法:
atable = [[6, 2, 3, 1], [3, 4, 2, 1], [4, 8, 7, 6], [8, 9, 3, 7]]
min_list = []
for l in atable:
min_list.append(min(l))
min_val = min(min_list)
答案 2 :(得分:-1)
针对您的特定问题...
min(min(a_table))
如@Prune所述,此操作无效。实际上,min(a_table)返回具有最小第一元素的子列表。