繁体   English   中英

numpy求解器:最大值

[英]Numpy solver : max value

我有2个变量:

期间结果

我如何告诉Numpy求解器(我假设那是我必须使用的)返回给我最高结果周期值 周期必须在1到100之间。

编辑:

眼下期间在14,给我的40的结果 期间为12。 给了我42的结果

我可以告诉numpy尝试在1到100之间的每个期间值,并且只得出结果最好的那个吗?

我想我真的不需要Numpy,我想知道这是否是一条路。

只需声明一个等于第一个周期值的变量,然后执行自己的循环,只要当前数字更大,就更改初始变量:

biggest = period(0)
index = 0

for i in range (1, 100)
    if period(i) > biggest
         biggest = period(i)
         index = i

return biggest

我不确定我是否理解这个问题,但是如果我这样做了,那么NumPy索引可能是最好的:

period = NP.arange(50)
result = NP.random.randint(1, 101, 50)

q = NP.argmax(result)   # gives index of largest value in the result array
result[q]               # returns the highest value in the result array
period[q]               # returns the value of period corresponding to 
                        # the highest value for result          

尚不清楚您拥有哪些数据,但这应该可以工作:

for period in periods:
    result = func(period)
    if result > resultmax:
        resultmax = result

或者,如果results是一个numpy.array使得results[period]是从结果period ,则只需

periodmax = results.argmax()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM