> For the complete documentation index, see [llms.txt](https://python-self-driving.gitbook.io/self-driving/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://python-self-driving.gitbook.io/self-driving/python/scipy-library.md).

# SciPy Library

s used for running scientific and mathematical computations. You are specifically going to use a part of the library that implements Gaussian distributions.

## Demo: Probability Density Function <a href="#demo-probability-density-function" id="demo-probability-density-function"></a>

```python
from scipy.stats import norm
import numpy as np

# our solution to calculate the probability density function
def gaussian_density(x, mu, sigma):
    return (1/np.sqrt(2*np.pi*np.power(sigma, 2.))) * np.exp(-np.power(x - mu, 2.) / (2 * np.power(sigma, 2.)))

print("Probability density function our solution: mu = 50, sigma = 10, x = 50")
print(gaussian_density(50, 50, 10))
print("\nProbability density function SciPy: mu = 50, sigma = 10, x = 50")
print(norm(loc = 50, scale = 10).pdf(50))
```

## Calculating Probability <a href="#calculating-probability" id="calculating-probability"></a>

Here are a few more examples of the cdf method. The code cell below prints out the probability that the temperature is between:

* -infinity and 25
* -infinity and 75
* -infinity and 125
* -infinity and +infinity

```python
print(norm(loc = 50, scale = 10).cdf(25))
print(norm(loc = 50, scale = 10).cdf(75))
print('%.20f' % norm(loc = 50, scale = 10).cdf(125)) # '%.20f' prints out 20 decimal places
print(norm(loc = 50, scale = 10).cdf(float('inf')))
```

```
0.00620966532578
0.993790334674
0.99999999999996813660
1.0
```
