Thursday, March 20, 2014

Navigating an Ordered Dictionary

While working with a fit result in python (using this package: https://github.com/lmfit/lmfit-py), I got the following:

In [104]: result.params['a']
Out[104]: <Parameter 'a', value=-0.017319048843571397 +/- 0.00387, bounds=[-inf:inf]>

Where a was one of the parameters that I fit for. I wanted to get the standard error (0.00387) to use in a plot, but I didn't know how!

Here's how to find the dictionary key words:

In [106]: result.params['a'].__dict__
Out[106]:
{'_val': -0.017319048843571397,
 'correl': {'std': 0.00014518047262818826},
 'deps': None,
 'expr': None,
 'from_internal': <function lmfit.parameter.<lambda>>,
 'init_value': 0,
 'max': inf,
 'min': -inf,
 'name': 'a',
 'stderr': 0.0038656946786479111,
 'user_value': 0,
 'vary': True}

So, result.params['a'].stderr returns the value. Simple enough!