我觉得这个问题有一个简单的答案,但我很难在不必编写很多行代码的情况下获得答案。我希望有人能给我一些东西,让我在 Python 中的列表推导方面更轻松。
我的是这样的:
highest_peak = sorted([(self.Y[x]-self.background_model[x]) for x in peaks_index_list])[0]
如何从发生这种情况的 peaks_index_list 中获取 highest_peak 的索引 (x)?
index_of_highest_peak = sorted(???)[0]
index_of_second_highest_peak = sorted(???)[1]
感谢您的帮助。
最佳答案
如果你使用 numpy 就可以
import numpy as np
highest_peak = np.asarray(highest_peak)
max_index = highest_peak.argmax()
关于python - 简单的python列表理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899194/