I wish to do the following:
1) Try a variety of input combinations to search for a best result
2) Reset all arrays as they were before each loop of the code
Every variable I am working with is in an array such as f[0,1,2,3,…]
The issue is likely in the resetting variables after each pass part, as the first pass works fine, but the residuals of the first pass cause the following iterations to break early..
Here is the pseudo for my method. So very simple, likely an issue with how Python handles data (object oriented)..
index_save = index
for input1 in [0.1,0.2,0.3,…]
for input2 in [10,20,30,…]
for input3 in [-0.1,-0.2,-0.3,…]
index = index_save #To reset the index and thus all arrays
while True:
index = index + 1
f[index] = *Function of inputs*
result = *Function of f and inputs*
if condition_met = true
break
if result > result_best
result_best = result
inputs_best = [input1,input2,input3]
解决方案
It turns out the answer to my question is as follows.
Using nested for loops to brute force combinations works (obviously). Using the method I outlined in the question works to do so. The part that requires care, is making sure you have successfully reset all variables on each pass. That means variables that are integers will have to be reset manually. This is in contrast to how I could reset all arrays simply by resetting the index.
integer_save = integer
index_save = index
for input in range
index = index_save
integer = integer_save
index = index + 1
array[index] = (physics functions based on input)
integer = (physics functions based on input)
今天的文章python中for循环嵌套执行顺序_python while循环分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/82397.html