3

What is the best way to save the result object from scipy.optimize.OptimizeResult, so that its parameters can be easily accesses from the saved file? I am currently saving the result as a string. But this way, when I need to refer to it again, I need to parse the entire string to identify objects such as the parameter array, or the function value. Is there a more direct way to just save the entire object as it is without any changes to the object type, so when I read the file again, I can access the object type in the same way as if it was output from the original function?

res1 = scipy.optimize.minimize(...)
parameter_array1 = res1.x #Here, I can access parameter array like so

save(res1) #Some function that will allow me to save the result object 

res2 = load(res1)

parameter_array2 = res2.x #I want to be able access the parameter array just as I did above

Shruti
  • 159
  • 1
  • 15
  • 1
    Have you looked into the Python standard library modules [pickle](https://docs.python.org/3/library/pickle.html) or [shelve](https://docs.python.org/3/library/shelve.html)? – Chris Greening Oct 07 '20 at 19:15
  • 1
    Oh wow, I just took a look at pickle, seems like that is exactly what I wanted! Thanks!! – Shruti Oct 07 '20 at 19:38

0 Answers0