Basic knowledge of Git to get the code • Code can be found at https://github.com/westover/OrlandoPythonUserGroup • These examples can be found in subdirectory Craig_Finch_NumPy_SciPy_matplotlib • See README.txt for details
indexing and slicing • Elements are strongly typed NumPy Type Subtypes (bits) Boolean Unsigned Integer C types, 8, 16, 32, 64 Integer C types, 8, 16, 32, 64 Floating Point C types, 8, 16, 32, 64, 96, 128 Complex Floating Point 2x32, 2x64, 2x96, 2x128 Python object references Much like a Python list
loops with vector operations • Demo: collision detection Premature optimization is the root of all evil (or at least most of it) in programming. Donald Knuth
controlled ◦ Results must be repeatable ◦ Results must be statistically significant • Tools ◦ Python cProfile ◦ Robert Kern’s line profiler https://pypi.python. org/pypi/line_profiler/1.0b3 ◦ Linux profilers ▪ oprofile ▪ valgrind (specifically, callgrind)
show how to optimize the calculation ◦ Also contains a decorator that times each function • Script NumPy/distance_benchmarking.py compares results ◦ Not a very sophisticated benchmarking tool • Script NumPy/distance_benchmarking.py ensures all functions return the same result
data • Use vector operations instead of loops whenever possible • If it’s still too slow…. ◦ Write C/C++/Fortran code ◦ Parallelize (multi-core, multi-server) • Understand NumPy, because it’s the foundation for: ◦ SciPy ◦ Pandas ◦ mpi4py
(scipy.special) • Integration (scipy.integrate) • Optimization (scipy.optimize) • Interpolation (scipy.interpolate) • Fourier Transforms (scipy.fftpack) • Signal Processing (scipy.signal) Continued on next slide... * or a candy store...
that overlap with NumPy ◦ SciPy’s linear algebra routines always run on the optimized system libraries (LAPACK, ATLAS, Intel Math Kernel Library, etc.) • Sparse matrix support • Extends NumPy’s statistical capabilities • Under active development ◦ New toys added constantly!
h(t) Output y(t) Example code: SciPy/LTI_simulation.py A linear time invariant (LTI) system is a generalization of the digital filter from the previous example:
Methods for impulse and step response • Create our own function ◦ Define a discrete-time step function ◦ Apply step function to input of system ◦ Compare results to results from SciPy class ◦ De-convolve to recover original signal
computing with Python ◦ Learn it well! • SciPy is a collection of mathematical and scientific tools • matplotlib is a technical plotting package ◦ Primarily 2D plotting ◦ Basic 3D plots available with mplot3d import mpl_toolkits.mplot3d