## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required ## Book Description

Build efficient, high-speed programs using the high-performance 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, step-by-step 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 one-stop 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, high-speed 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

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

1. NumPy Beginner's Guide Third Edition
2. NumPy Beginner's Guide Third Edition
3. Credits
6. www.PacktPub.com
1. Support files, eBooks, discount offers, and more
7. Preface
1. What is NumPy?
2. History
3. Why use NumPy?
4. Limitations of NumPy
5. What this book covers
6. What you need for this book
7. Who this book is for
8. Sections
9. Time for action – heading
10. Conventions
12. Customer support
8. 1. NumPy Quick Start
1. Python
2. Time for action – installing Python on different operating systems
3. The Python help system
4. Time for action – using the Python help system
5. Basic arithmetic and variable assignment
6. Time for action – using Python as a calculator
7. Time for action – assigning values to variables
8. The print() function
9. Time for action – printing with the print() function
11. Time for action – commenting code
12. The if statement
13. Time for action – deciding with the if statement
14. The for loop
15. Time for action – repeating instructions with loops
16. Python functions
17. Time for action – defining functions
18. Python modules
19. Time for action – importing modules
20. NumPy on Windows
21. Time for action – installing NumPy, matplotlib, SciPy, and IPython on Windows
22. NumPy on Linux
23. Time for action – installing NumPy, matplotlib, SciPy, and IPython on Linux
24. NumPy on Mac OS X
25. Time for action – installing NumPy, SciPy, matplotlib, and IPython with MacPorts or Fink
26. Building from source
27. Arrays
28. Time for action – adding vectors
29. IPython – an interactive shell
30. Online resources and help
31. Summary
9. 2. Beginning with NumPy Fundamentals
1. NumPy array object
2. Time for action – creating a multidimensional array
3. Time for action – creating a record data type
4. One-dimensional slicing and indexing
5. Time for action – slicing and indexing multidimensional arrays
6. Time for action – manipulating array shapes
7. Time for action – stacking arrays
8. Time for action – splitting arrays
9. Time for action – converting arrays
10. Summary
10. 3. Getting Familiar with Commonly Used Functions
1. File I/O
2. Time for action – reading and writing files
3. Comma-seperated value files
5. Volume Weighted Average Price
6. Time for action – calculating Volume Weighted Average Price
7. Value range
8. Time for action – finding highest and lowest values
9. Statistics
10. Time for action – performing simple statistics
11. Stock returns
12. Time for action – analyzing stock returns
13. Dates
14. Time for action – dealing with dates
15. Time for action – using the datetime64 data type
16. Weekly summary
17. Time for action – summarizing data
18. Average True Range
19. Time for action – calculating the Average True Range
20. Simple Moving Average
21. Time for action – computing the Simple Moving Average
22. Exponential Moving Average
23. Time for action – calculating the Exponential Moving Average
24. Bollinger Bands
25. Time for action – enveloping with Bollinger Bands
26. Linear model
27. Time for action – predicting price with a linear model
28. Trend lines
29. Time for action – drawing trend lines
30. Methods of ndarray
31. Time for action – clipping and compressing arrays
32. Factorial
33. Time for action – calculating the factorial
34. Missing values and Jackknife resampling
35. Time for action – handling NaNs with the nanmean(), nanvar(), and nanstd() functions
36. Summary
11. 4. Convenience Functions for Your Convenience
1. Correlation
2. Time for action – trading correlated pairs
3. Polynomials
4. Time for action – fitting to polynomials
5. On-balance volume
6. Time for action – balancing volume
7. Simulation
8. Time for action – avoiding loops with vectorize()
9. Smoothing
10. Time for action – smoothing with the hanning() function
11. Initialization
12. Time for action – creating value initialized arrays with the full() and full_like() functions
13. Summary
12. 5. Working with Matrices and ufuncs
1. Matrices
2. Time for action – creating matrices
3. Creating a matrix from other matrices
4. Time for action – creating a matrix from other matrices
5. Universal functions
6. Time for action – creating universal functions
7. Universal function methods
8. Time for action – applying the ufunc methods to the add function
9. Arithmetic functions
10. Time for action – dividing arrays
11. Modulo operation
12. Time for action – computing the modulo
13. Fibonacci numbers
14. Time for action – computing Fibonacci numbers
15. Lissajous curves
16. Time for action – drawing Lissajous curves
17. Square waves
18. Time for action – drawing a square wave
19. Sawtooth and triangle waves
20. Time for action – drawing sawtooth and triangle waves
21. Bitwise and comparison functions
22. Time for action – twiddling bits
23. Fancy indexing
24. Time for action – fancy indexing in-place for ufuncs with the at() method
25. Summary
13. 6. Moving Further with NumPy Modules
1. Linear algebra
2. Time for action – inverting matrices
3. Solving linear systems
4. Time for action – solving a linear system
5. Finding eigenvalues and eigenvectors
6. Time for action – determining eigenvalues and eigenvectors
7. Singular value decomposition
8. Time for action – decomposing a matrix
9. Pseudo inverse
10. Time for action – computing the pseudo inverse of a matrix
11. Determinants
12. Time for action – calculating the determinant of a matrix
13. Fast Fourier transform
14. Time for action – calculating the Fourier transform
15. Shifting
16. Time for action – shifting frequencies
17. Random numbers
18. Time for action – gambling with the binomial
19. Hypergeometric distribution
20. Time for action – simulating a game show
21. Continuous distributions
22. Time for action – drawing a normal distribution
23. Lognormal distribution
24. Time for action – drawing the lognormal distribution
25. Bootstrapping in statistics
26. Time for action – sampling with numpy.random.choice()
27. Summary
14. 7. Peeking into Special Routines
1. Sorting
2. Time for action – sorting lexically
3. Time for action – partial sorting via selection for a fast median with the partition() function
4. Complex numbers
5. Time for action – sorting complex numbers
6. Searching
7. Time for action – using searchsorted
8. Array elements extraction
9. Time for action – extracting elements from an array
10. Financial functions
11. Time for action – determining the future value
12. Present value
13. Time for action – getting the present value
14. Net present value
15. Time for action – calculating the net present value
16. Internal rate of return
17. Time for action – determining the internal rate of return
18. Periodic payments
19. Time for action – calculating the periodic payments
20. Number of payments
21. Time for action – determining the number of periodic payments
22. Interest rate
23. Time for action – figuring out the rate
24. Window functions
25. Time for action – plotting the Bartlett window
26. Blackman window
27. Time for action – smoothing stock prices with the Blackman window
28. Hamming window
29. Time for action – plotting the Hamming window
30. Kaiser window
31. Time for action – plotting the Kaiser window
32. Special mathematical functions
33. Time for action – plotting the modified Bessel function
34. sinc
35. Time for action – plotting the sinc function
36. Summary
15. 8. Assuring Quality with Testing
1. Assert functions
2. Time for action – asserting almost equal
3. Approximately equal arrays
4. Time for action – asserting approximately equal
5. Almost equal arrays
6. Time for action – asserting arrays almost equal
7. Equal arrays
8. Time for action – comparing arrays
9. Ordering arrays
10. Time for action – checking the array order
11. Object comparison
12. Time for action – comparing objects
13. String comparison
14. Time for action – comparing strings
15. Floating-point comparisons
16. Time for action – comparing with assert_array_almost_equal_nulp
17. Comparison of floats with more ULPs
18. Time for action – comparing using maxulp of 2
19. Unit tests
20. Time for action – writing a unit test
21. Nose test decorators
22. Time for action – decorating tests
23. Docstrings
24. Time for action – executing doctests
25. Summary
16. 9. Plotting with matplotlib
1. Simple plots
2. Time for action – plotting a polynomial function
3. Plot format string
4. Time for action – plotting a polynomial and its derivatives
5. Subplots
6. Time for action – plotting a polynomial and its derivatives
7. Finance
8. Time for action – plotting a year's worth of stock quotes
9. Histograms
10. Time for action – charting stock price distributions
11. Logarithmic plots
12. Time for action – plotting stock volume
13. Scatter plots
14. Time for action – plotting price and volume returns with a scatter plot
15. Fill between
16. Time for action – shading plot regions based on a condition
17. Legend and annotations
18. Time for action – using a legend and annotations
19. Three-dimensional plots
20. Time for action – plotting in three dimensions
21. Contour plots
22. Time for action – drawing a filled contour plot
23. Animation
24. Time for action – animating plots
25. Summary
17. 10. When NumPy Is Not Enough – SciPy and Beyond
1. MATLAB and Octave
3. Statistics
4. Time for action – analyzing random values
5. Sample comparison and SciKits
6. Time for action – comparing stock log returns
7. Signal processing
8. Time for action – detecting a trend in QQQ
9. Fourier analysis
10. Time for action – filtering a detrended signal
11. Mathematical optimization
12. Time for action – fitting to a sine
13. Numerical integration
14. Time for action – calculating the Gaussian integral
15. Interpolation
16. Time for action – interpolating in one dimension
17. Image processing
18. Time for action – manipulating Lena
19. Audio processing
20. Time for action – replaying audio clips
21. Summary
18. 11. Playing with Pygame
1. Pygame
2. Time for action – installing Pygame
3. Hello World
4. Time for action – creating a simple game
5. Animation
6. Time for action – animating objects with NumPy and Pygame
7. matplotlib
8. Time for Action – using matplotlib in Pygame
9. Surface pixels
10. Time for Action – accessing surface pixel data with NumPy
11. Artificial Intelligence
12. Time for Action – clustering points
13. OpenGL and Pygame
14. Time for Action – drawing the Sierpinski gasket
15. Simulation game with Pygame
16. Time for Action – simulating life
17. Summary