(Press `?`

for help, `n`

and `p`

for next and previous slide; usage hints)

David Wright

February 27 2021

- What are NumPy, SciPy, and Matplotlib?
- Basic usage and functionality
- Demos

- NumPy is the fundamental package for scientific computing in Python.
- Python library that provides the following:
- Multidimensional array object (
**ndarray**) - Various derived objects (such as masked arrays and matrices)
Assortment of routines for fast operations on arrays

- Multidimensional array object (

- Built on NumPy
- Provides numerical routines, such as:
- Numerical integration
- Interpolation
- Optimization
- Linear algebra
- Statistics

- Library for creating visualizations in Python
- Static,
- Animated,
- and Interactive visualizations

- Basic data type is
**ndarray**

import numpy as np x = np.array([[1,2,3],[4,5,6]]) print(type(x)) print(x.shape) print(x)

<class 'numpy.ndarray'> (2, 3) [[1 2 3] [4 5 6]]

- Pre-compiled C code runs behind the scenes
- Gives us speed and memory efficiency

As an example, I’ll show how matrix multiplication can be done very easily with NumPy

import numpy as np np.set_printoptions(suppress=True) np.set_printoptions(precision=3) x = np.array([1,0]) th = np.pi / 2 y = np.array([[np.cos(th), -np.sin(th)], [np.sin(th), np.cos(th)]]) rot = np.matmul(y,x) print(rot)

[0. 1.]

**Note**: by default, the*****operator performs element-wise multiplication on NumPy arrays

- SciPy is split into a number of
**subpackages**

Subpackage | Description |
---|---|

cluster |
Clustering algorithms |

constants |
Physical and mathematical constants |

fftpack |
Fast Fourier Transform routines |

integrate |
Integration and ordinary differential equation solvers |

interpolate |
Interpolation and smoothing splines |

io |
Input and Output |

linalg |
Linear Algebra |

ndimage |
N-dimensional image processing |

odr |
Orthogonal distance regression |

Subpackage | Description |
---|---|

optimize |
Optimization and root-finding routines |

signal |
Signal processing |

sparse |
Sparse matrices and associated routines |

spatial |
Spatial data structures and algorithms |

special |
Special functions |

stats |
Statistical distributions and functions |

- Standard practice is to import only the subpackages you need

from scipy import optimize

The basic usage is as follows

import matplotlib.pyplot as plt plt.plot(#your-data)

- Matplotlib has many different plotting options
- Histograms
- Bar Charts
- Errorbar
- Scatter
- 3D
- Contours, and more

Visit the link below to get an online instance of a Jupyter Notebook with some demos.

- Snippets of Dr. Joseph Harrington’s Python demos were used with his permission
*ThinkPython*was used as a reference