How to calculate probability in normal distribution given mean, std in Python? I can always explicitly code my own function according to the definition like the OP in this question did: Calculating Probability of a Random Variable in a Distribution in Python
Just wondering if there is a library function call will allow you to do this. In my imagine it would like this:
nd = NormalDistribution(mu=100, std=12)
p = nd.prob(98)
There is a similar question in Perl: How can I compute the probability at a point given a normal distribution in Perl?. But I didn’t see one in Python.
Numpy has a random.normal function, but it’s like sampling, not exactly what I want.
There’s one in scipy.stats:
[One thing to beware of — just a tip — is that the parameter passing is a little broad. Because of the way the code is set up, if you accidentally write
scipy.stats.norm(mean=100, std=12)instead ofscipy.stats.norm(100, 12)orscipy.stats.norm(loc=100, scale=12), then it’ll accept it, but silently discard those extra keyword arguments and give you the default (0,1).]