there are (say) two functions, norm and uniform, both of which take the arguments scale and loc. I would like to have a function called pick_a_distribution, which selects which distribution to pick and then assigns the appropriate arguments and does some other stuff. But I also want the user to be able to define (say) a value for one argument and pass only that, rather having to define the whole list of arguments.
I have managed to write some code that works, if I pass the full list of arguments (and therefore I need to know what the default values are, for the ones I do not really want to pass).
Is there a way to be more efficient (in the above example, would there be a way to only pass the 'loc' argument)?
below is some code that works . . .
from scipy.stats import norm, genlogistic, uniform, expon
import math
distribution = {'1': 'normal', '2': 'uniform', '3': 'genlogistic', '4': 'exponential', '5': 'error'}
def mydistr(distr,numofsims, myargument):
switcher = {
'1': norm(*myargument),
'2': uniform(*myargument),
'3': genlogistic(*myargument),
'4': expon(*myargument)
}
myobs = switcher.get(distr, 'Error in getting distribution')
return myobs.rvs(numofsims)
print(mydistr( myargument = [2,80], numofsims = 100000, distr = '2' ).mean())
and some that doesnt. . . (same imports as before)
def mydistr(distr,numofsims, myargument):
switcher = {
'1': norm(*myargument),
'2': uniform(**myargument),
'3': genlogistic(*myargument),
'4': expon(*myargument)
}
myobs = switcher.get(distr, 'Error in getting distribution')
return myobs.rvs(numofsims)
print(mydistr( myargument = {loc:80}, numofsims = 100000, distr = '2' ).mean())
I've also tried to have the following for myargument in the final call: = ({loc:80}), = (loc,80) and tried 'loc' as well;
I get that name 'loc' is not defined, and when i put it in '' I get some comparison errors.
Any comments much appreciated, thank you in advance :)