我有一系列的可能性:

proba =  :[[0.254 0.556 0.025] [0.898 0567 .112]]


希望每个最大值都为[[0.556] [0.898]]

我该怎么办?
尝试了2种方法:

 1. max(sublist) for sublist in proba
 2. proba = map(max,proba)


并得到错误"TypeError: 'numpy.float32' object is not iterable"

有什么建议吗?

最佳答案

我注意到您的代码中存在一些问题,
首先,您的数据列表格式不正确,
逗号缺失,等号右边有一个额外的“:”

proba = [[0.254, 0.556, 0.025], [0.898, 0.567, .112]]


然后您可以得到如下答案:

max_ = [max(i) for i in proba]

关于python - TypeError:“numpy.float32”对象不可迭代,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47717999/

10-12 17:27