Python找到数组的最后一个最小值 [英] Python find last minimum of an array

查看:372
本文介绍了Python找到数组的最后一个最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像上面图像一样的python价格数组:

i have a python price array like above image:

[100,200,150,300,250,400]

我想找到图像上显示的红色圆圈之类的数组的最后一个最小值.

i want to find last minimum of array like red circle shown on the image.

结果:[250]

推荐答案

最简单的策略是遍历列表,并存储找到的每个局部最小值的值,最后以变量中存储的最后一个最小值结束.

The simplest strategy would be to iterate over the list and store the value of every local minimum found, ending with the last minimum stored in the variable.

lst = [100,200,150,300,250,400]
current_min = -1
for i in range(1, len(lst) - 1):
   if lst[i - 1] > lst[i] and lst[i + 1] > lst[i]:
     current_min = lst[i]

这篇关于Python找到数组的最后一个最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆