本文介绍了如何在列表的一部分上找到numpy.argmax()并保存索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
array = [1, 2, 3, 4, 5, 6, 7, 8];
我只需要为数组中的最后4个元素找到numpy.argmax
.
I need to find numpy.argmax
only for last 4 elements in array.
这无效,因为索引丢失:
This does not works, because index is losted:
>>> array = [1, 2, 3, 4, 5, 6, 7, 8];
>>> print (array[4:8]);
[5, 6, 7, 8]
>>> print (np.argmax(array[4:8]) );
3
结果必须为7
推荐答案
简单的方法是,我不知道,只需在输出中添加4?假设它并不总是4,则可以始终这样做:
The simple approach would be to, I dunno, just add a 4 to the output? Assuming it isn't always 4, you could always do this:
print np.argmax(array[x : 8]) + x
这篇关于如何在列表的一部分上找到numpy.argmax()并保存索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!