Book description
Build efficient, highspeed programs using the highperformance NumPy mathematical library
In Detail
In today's world of science and technology, it's all about speed and flexibility. When it comes to scientific computing, NumPy tops the list. NumPy will give you both speed and high productivity. This book will walk you through NumPy with clear, stepbystep examples and just the right amount of theory. The book focuses on the fundamentals of NumPy, including array objects, functions, and matrices, each of them explained with practical examples. You will then learn about different NumPy modules while performing mathematical operations such as calculating the Fourier transform, finding the inverse of a matrix, and determining eigenvalues, among many others. This book is a onestop solution to knowing the ins and outs of the vast NumPy library, empowering you to use its wide range of mathematical features to build efficient, highspeed programs.
What You Will Learn
 Install NumPy, matplotlib, SciPy, and IPython on various operating systems
 Use NumPy array objects to perform array operations
 Familiarize yourself with commonly used NumPy functions
 Use NumPy matrices for matrix algebra
 Work with the NumPy modules to perform various algebraic operations
 Test NumPy code with the numpy.testing module
 Plot simple plots, subplots, histograms, and more with matplotlib
Table of contents

NumPy Beginner's Guide Third Edition
 Table of Contents
 NumPy Beginner's Guide Third Edition
 Credits
 About the Author
 About the Reviewers
 www.PacktPub.com
 Preface

1. NumPy Quick Start
 Python
 Time for action – installing Python on different operating systems
 The Python help system
 Time for action – using the Python help system
 Basic arithmetic and variable assignment
 Time for action – using Python as a calculator
 Time for action – assigning values to variables
 The print() function
 Time for action – printing with the print() function
 Code comments
 Time for action – commenting code
 The if statement
 Time for action – deciding with the if statement
 The for loop
 Time for action – repeating instructions with loops
 Python functions
 Time for action – defining functions
 Python modules
 Time for action – importing modules
 NumPy on Windows
 Time for action – installing NumPy, matplotlib, SciPy, and IPython on Windows
 NumPy on Linux
 Time for action – installing NumPy, matplotlib, SciPy, and IPython on Linux
 NumPy on Mac OS X
 Time for action – installing NumPy, SciPy, matplotlib, and IPython with MacPorts or Fink
 Building from source
 Arrays
 Time for action – adding vectors
 IPython – an interactive shell
 Online resources and help
 Summary

2. Beginning with NumPy Fundamentals
 NumPy array object
 Time for action – creating a multidimensional array
 Time for action – creating a record data type
 Onedimensional slicing and indexing
 Time for action – slicing and indexing multidimensional arrays
 Time for action – manipulating array shapes
 Time for action – stacking arrays
 Time for action – splitting arrays
 Time for action – converting arrays
 Summary

3. Getting Familiar with Commonly Used Functions
 File I/O
 Time for action – reading and writing files
 Commaseperated value files
 Time for action – loading from CSV files
 Volume Weighted Average Price
 Time for action – calculating Volume Weighted Average Price
 Value range
 Time for action – finding highest and lowest values
 Statistics
 Time for action – performing simple statistics
 Stock returns
 Time for action – analyzing stock returns
 Dates
 Time for action – dealing with dates
 Time for action – using the datetime64 data type
 Weekly summary
 Time for action – summarizing data
 Average True Range
 Time for action – calculating the Average True Range
 Simple Moving Average
 Time for action – computing the Simple Moving Average
 Exponential Moving Average
 Time for action – calculating the Exponential Moving Average
 Bollinger Bands
 Time for action – enveloping with Bollinger Bands
 Linear model
 Time for action – predicting price with a linear model
 Trend lines
 Time for action – drawing trend lines
 Methods of ndarray
 Time for action – clipping and compressing arrays
 Factorial
 Time for action – calculating the factorial
 Missing values and Jackknife resampling
 Time for action – handling NaNs with the nanmean(), nanvar(), and nanstd() functions
 Summary

4. Convenience Functions for Your Convenience
 Correlation
 Time for action – trading correlated pairs
 Polynomials
 Time for action – fitting to polynomials
 Onbalance volume
 Time for action – balancing volume
 Simulation
 Time for action – avoiding loops with vectorize()
 Smoothing
 Time for action – smoothing with the hanning() function
 Initialization
 Time for action – creating value initialized arrays with the full() and full_like() functions
 Summary

5. Working with Matrices and ufuncs
 Matrices
 Time for action – creating matrices
 Creating a matrix from other matrices
 Time for action – creating a matrix from other matrices
 Universal functions
 Time for action – creating universal functions
 Universal function methods
 Time for action – applying the ufunc methods to the add function
 Arithmetic functions
 Time for action – dividing arrays
 Modulo operation
 Time for action – computing the modulo
 Fibonacci numbers
 Time for action – computing Fibonacci numbers
 Lissajous curves
 Time for action – drawing Lissajous curves
 Square waves
 Time for action – drawing a square wave
 Sawtooth and triangle waves
 Time for action – drawing sawtooth and triangle waves
 Bitwise and comparison functions
 Time for action – twiddling bits
 Fancy indexing
 Time for action – fancy indexing inplace for ufuncs with the at() method
 Summary

6. Moving Further with NumPy Modules
 Linear algebra
 Time for action – inverting matrices
 Solving linear systems
 Time for action – solving a linear system
 Finding eigenvalues and eigenvectors
 Time for action – determining eigenvalues and eigenvectors
 Singular value decomposition
 Time for action – decomposing a matrix
 Pseudo inverse
 Time for action – computing the pseudo inverse of a matrix
 Determinants
 Time for action – calculating the determinant of a matrix
 Fast Fourier transform
 Time for action – calculating the Fourier transform
 Shifting
 Time for action – shifting frequencies
 Random numbers
 Time for action – gambling with the binomial
 Hypergeometric distribution
 Time for action – simulating a game show
 Continuous distributions
 Time for action – drawing a normal distribution
 Lognormal distribution
 Time for action – drawing the lognormal distribution
 Bootstrapping in statistics
 Time for action – sampling with numpy.random.choice()
 Summary

7. Peeking into Special Routines
 Sorting
 Time for action – sorting lexically
 Time for action – partial sorting via selection for a fast median with the partition() function
 Complex numbers
 Time for action – sorting complex numbers
 Searching
 Time for action – using searchsorted
 Array elements extraction
 Time for action – extracting elements from an array
 Financial functions
 Time for action – determining the future value
 Present value
 Time for action – getting the present value
 Net present value
 Time for action – calculating the net present value
 Internal rate of return
 Time for action – determining the internal rate of return
 Periodic payments
 Time for action – calculating the periodic payments
 Number of payments
 Time for action – determining the number of periodic payments
 Interest rate
 Time for action – figuring out the rate
 Window functions
 Time for action – plotting the Bartlett window
 Blackman window
 Time for action – smoothing stock prices with the Blackman window
 Hamming window
 Time for action – plotting the Hamming window
 Kaiser window
 Time for action – plotting the Kaiser window
 Special mathematical functions
 Time for action – plotting the modified Bessel function
 sinc
 Time for action – plotting the sinc function
 Summary

8. Assuring Quality with Testing
 Assert functions
 Time for action – asserting almost equal
 Approximately equal arrays
 Time for action – asserting approximately equal
 Almost equal arrays
 Time for action – asserting arrays almost equal
 Equal arrays
 Time for action – comparing arrays
 Ordering arrays
 Time for action – checking the array order
 Object comparison
 Time for action – comparing objects
 String comparison
 Time for action – comparing strings
 Floatingpoint comparisons
 Time for action – comparing with assert_array_almost_equal_nulp
 Comparison of floats with more ULPs
 Time for action – comparing using maxulp of 2
 Unit tests
 Time for action – writing a unit test
 Nose test decorators
 Time for action – decorating tests
 Docstrings
 Time for action – executing doctests
 Summary

9. Plotting with matplotlib
 Simple plots
 Time for action – plotting a polynomial function
 Plot format string
 Time for action – plotting a polynomial and its derivatives
 Subplots
 Time for action – plotting a polynomial and its derivatives
 Finance
 Time for action – plotting a year's worth of stock quotes
 Histograms
 Time for action – charting stock price distributions
 Logarithmic plots
 Time for action – plotting stock volume
 Scatter plots
 Time for action – plotting price and volume returns with a scatter plot
 Fill between
 Time for action – shading plot regions based on a condition
 Legend and annotations
 Time for action – using a legend and annotations
 Threedimensional plots
 Time for action – plotting in three dimensions
 Contour plots
 Time for action – drawing a filled contour plot
 Animation
 Time for action – animating plots
 Summary

10. When NumPy Is Not Enough – SciPy and Beyond
 MATLAB and Octave
 Time for action – saving and loading a .mat file
 Statistics
 Time for action – analyzing random values
 Sample comparison and SciKits
 Time for action – comparing stock log returns
 Signal processing
 Time for action – detecting a trend in QQQ
 Fourier analysis
 Time for action – filtering a detrended signal
 Mathematical optimization
 Time for action – fitting to a sine
 Numerical integration
 Time for action – calculating the Gaussian integral
 Interpolation
 Time for action – interpolating in one dimension
 Image processing
 Time for action – manipulating Lena
 Audio processing
 Time for action – replaying audio clips
 Summary

11. Playing with Pygame
 Pygame
 Time for action – installing Pygame
 Hello World
 Time for action – creating a simple game
 Animation
 Time for action – animating objects with NumPy and Pygame
 matplotlib
 Time for Action – using matplotlib in Pygame
 Surface pixels
 Time for Action – accessing surface pixel data with NumPy
 Artificial Intelligence
 Time for Action – clustering points
 OpenGL and Pygame
 Time for Action – drawing the Sierpinski gasket
 Simulation game with Pygame
 Time for Action – simulating life
 Summary

A. Pop Quiz Answers
 Chapter 1, NumPy Quick Start
 Chapter 2, Beginning with NumPy Fundamentals
 Chapter 3, Getting Familiar with Commonly Used Functions
 Chapter 4, Convenience Functions for Your Convenience
 Chapter 5, Working with Matrices and ufuncs
 Chapter 6, Move Further with NumPy Modules
 Chapter 7, Peeking into Special Routines
 Chapter 8, Assuring Quality with Testing
 Chapter 9, Plotting with matplotlib
 Chapter 10, When NumPy Is Not Enough –Scipy and Beyond
 B. Additional Online Resources
 C. NumPy Functions' References
 Index
Product information
 Title: NumPy : Beginner's Guide  Third Edition
 Author(s):
 Release date: June 2015
 Publisher(s): Packt Publishing
 ISBN: 9781785281969
You might also like
book
NumPy Essentials
Boost your scientific and analytic capabilities in no time at all by discovering how to build …
book
Advanced Python Programming  Second Edition
Write fast, robust, and highly reusable applications using Python's internal optimization, stateoftheart performancebenchmarking tools, and cuttingedge …
book
Python in a Nutshell, 3rd Edition
Useful in many roles, from design and prototyping to testing, deployment, and maintenance, Python is consistently …
book
Numerical Python: Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib
Leverage the numerical and mathematical modules in Python and its standard library as well as popular …