SciPy - Python Library for Mathematical Functions

This section provides a tutorial example on how to install Python 3 SciPy library on macOS computers. SciPy is widely used by Python users for mathematical functions required in neural network models.

What Is SciPy? SciPy is an open-source Python library for scientific computing developed initially by Travis Oliphant and now maintained by the SciPy community.

If you want to build neural network models in Python, you should install SciPy and get familiar with its functionalities by following this tutorial. This is because neural network models require lots of mathematical functions, which are provided in SciPy.

1. Install SciPy library using the "pip" (Package Installer for Python) command:

herong\$ python --version
Python 3.8.0

herong\$ sudo pip install scipy
Collecting scipy
Installing collected packages: scipy
Successfully installed scipy-1.5.0

3. Verify SciPy installation by importing "scipy" package, retrieving its version string, and calling some statistical functions.

herong\$ python
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27)

>>> import scipy as sp
>>> sp.v2.14
'1.5.0'

>>> import numpy as np
>>> s = np.random.rand(1000000)

>>> from scipy import stats

>>> stats.tmean(s)
0.5000266615822236

>>> stats.tvar(s)
0.08345433925168123

Note that:

• random.rand() function from NumPy library was used to generate a dataset of 1,000,000 random numbers between 0 and 1.
• stats.tmean() function from SciPy library calculated the mean value of the dataset as 0.5000266615822236, which is very close to the theoretically value of 0.5.
• stats.tvar() function from SciPy library calculated the variance value of the dataset as 0.08345433925168123, which is very close to the theoretically value of 0.08333... (or 1/12).

Cool! You have SciPy library ready on your Python environment for scientific computing.

For more readings on SciPy, visit SciPy documentation Website at https://docs.scipy.org/doc/scipy/reference/.