You are previewing NumPy 1.5.
O'Reilly logo
NumPy 1.5

Book Description

An action-packed guide for the easy-to-use, high performance, Python based free open source NumPy mathematical library using real-world examples

  • The first and only book that truly explores NumPy practically

  • Perform high performance calculations with clean and efficient NumPy code

  • Analyze large data sets with statistical functions

  • Execute complex linear algebra and mathematical computations

  • In Detail

    In today's world of science and technology, the hype is all about speed and flexibility. When it comes to scientific computing, NumPy is on the top of the list. NumPy is the fundamental package needed for scientific computing with Python. NumPy will give you both speed and high productivity. Save thousands of dollars on expensive software, while keeping all the flexibility and power of your favourite programming language.

    NumPy 1.5 Beginner's Guide will teach you about NumPy from scratch. It includes everything from installation, functions, matrices, and modules to testing, all explained with appropriate examples.

    Numpy 1.5 Beginner's Guide will teach you about installing and using NumPy and related concepts.

    This book will give you a solid foundation in NumPy arrays and universal functions. At the end of the book, we will explore related scientific computing projects such as Matplotlib for plotting and the SciPy project through examples.

    NumPy 1.5 Beginner's Guide will help you be productive with NumPy and write clean and fast code.

    Table of Contents

    1. NumPy 1.5
      1. Table of Contents
      2. NumPy 1.5
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      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. Conventions
        9. Time for action – heading
          1. What just happened?
          2. Pop quiz – heading
          3. Have a go hero – heading
        10. Reader feedback
        11. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. NumPy Quick Start
        1. Python
        2. Time for action – installing Python on different operating systems
          1. What just happened?
        3. Windows
        4. Time for action – installing NumPy on Windows
          1. What just happened?
        5. Linux
        6. Time for action – installing NumPy on Linux
          1. What just happened?
        7. Mac OS X
        8. Time for action – installing NumPy on Mac OS X with a GUI installer
          1. What just happened?
        9. Time for action – installing NumPy with MacPorts or Fink
          1. What just happened?
        10. Building from source
        11. Vectors
        12. Time for action – adding vectors
          1. What just happened?
          2. Pop Quiz - functioning of arange function
          3. Have a go hero – continue the analysis
        13. IPython—an interactive shell
        14. Online resources and help
        15. Summary
      9. 2. Beginning with NumPy Fundamentals
        1. NumPy array object
        2. Time for action – creating a multidimensional array
          1. What just happened?
          2. Pop quiz – the shape of ndarray
          3. Have a go hero – create a 3-by-3 matrix
          4. Selecting elements
          5. NumPy numerical types
          6. Data type objects
          7. Character codes
          8. dtype constructors
          9. dtype attributes
        3. Time for action – creating a record data type
          1. What just happened?
        4. One-dimensional slicing and indexing
        5. Time for action – slicing and indexing multidimensional arrays
          1. What just happened?
        6. Time for action – manipulating array shapes
          1. What just happened?
          2. Stacking
        7. Time for action – stacking arrays
          1. What just happened?
          2. Splitting
        8. Time for action – splitting arrays
          1. What just happened?
          2. Array attributes
        9. Time for action – converting arrays
          1. What just happened?
        10. Summary
      10. 3. Get into Terms with Commonly Used Functions
        1. File I/O
        2. Time for action – reading and writing files
          1. Identity matrix creation
          2. What just happened?
        3. CSV files
        4. Time for action – loading from CSV files
          1. What just happened?
        5. Volume weighted average price
        6. Time for action – calculating volume weighted average price
          1. What just happened?
          2. The mean function
          3. Time weighted average price
          4. Pop quiz – computing the weighted average
          5. Have a go hero – calculating other averages
        7. Value range
        8. Time for action – finding highest and lowest values
          1. What just happened?
        9. Statistics
        10. Time for action – doing simple statistics
          1. What just happened?
        11. Stock returns
        12. Time for action – analyzing stock returns
          1. What just happened?
        13. Dates
        14. Time for action – dealing with dates
          1. What just happened?
          2. Have a go hero – looking at VWAP and TWAP
        15. Weekly summary
        16. Time for action – summarizing data
          1. What just happened?
          2. Have a go hero – improving the code
        17. Average true range
        18. Time for action – calculating the average true range
          1. What just happened?
          2. Have a go hero – taking the minimum function for a spin
        19. Simple moving average
        20. Time for action – computing the simple moving average
          1. What just happened?
        21. Exponential moving average
        22. Time for action – calculating the exponential moving average
          1. What just happened?
        23. Bollinger bands
        24. Time for action – enveloping with Bollinger bands
          1. What just happened?
          2. Have a go hero – switching to exponential moving average
        25. Linear model
        26. Time for action – predicting price with a linear model
          1. What just happened?
        27. Trend lines
        28. Time for action – drawing trend lines
          1. What just happened?
        29. Methods of ndarray
        30. Time for action – clipping and compressing arrays
          1. What just happened?
        31. Factorial
        32. Time for action – calculating the factorial
          1. What just happened?
        33. Summary
      11. 4. Convenience Functions for Your Convenience
        1. Correlation
        2. Time for action – trading correlated pairs
          1. What just happened?
          2. Pop quiz – calculating covariance
        3. Polynomials
        4. Time for action – fitting to polynomials
          1. What just happened?
          2. Have a go hero – improving the fit
        5. On-balance volume
        6. Time for action – balancing volume
          1. What just happened?
        7. The mode
        8. Time for action – determining the mode of stock returns
          1. What just happened?
        9. Simulation
        10. Time for action – avoiding loops with vectorize
          1. What just happened?
          2. Have a go hero – analyzing consecutive wins and losses
        11. Smoothing
        12. Time for action – smoothing with the hanning function
          1. What just happened?
          2. Have a go hero – smoothing variations
        13. Summary
      12. 5. Working with Matrices and ufuncs
        1. Matrices
        2. Time for action – creating matrices
          1. What just happened?
        3. Creating a matrix from other matrices
        4. Time for action – creating a matrix from other matrices
          1. What just happened?
          2. Pop quiz – defining a matrix with a string
        5. Universal functions
        6. Time for action – creating universal function
          1. What just happened?
        7. Universal function methods
        8. Time for action – applying the ufunc methods on add
          1. What just happened?
        9. Arithmetic functions
        10. Time for action – dividing arrays
          1. What just happened?
          2. Have a go hero – experimenting with __future__.division
        11. Modulo operation
        12. Time for action – computing the modulo
          1. What just happened?
        13. Fibonacci numbers
        14. Time for action – computing Fibonacci numbers
          1. What just happened?
          2. Have a go hero – timing the calculations
        15. Lissajous curves
        16. Time for action – drawing Lissajous curves
          1. What just happened?
        17. Square waves
        18. Time for action – drawing a square wave
          1. What just happened?
          2. Have a go hero – getting rid of the loop
        19. Sawtooth and triangle waves
        20. Time for action – drawing sawtooth and triangle waves
          1. What just happened?
          2. Have a go hero – getting rid of the loop
        21. Bitwise and comparison functions
        22. Time for action – twiddling bits
          1. What just happened?
        23. Summary
      13. 6. Move Further with NumPy Modules
        1. Linear algebra
        2. Time for action – inverting matrices
          1. What just happened?
          2. Pop quiz – creating a matrix
          3. Have a go hero – inverting your own matrix
        3. Solving linear systems
        4. Time for action – solving a linear system
          1. What just happened?
        5. Finding eigenvalues and eigenvectors
        6. Time for action – determining eigenvalues and eigenvectors
          1. What just happened?
        7. Singular value decomposition
        8. Time for action – decomposing a matrix
          1. What just happened?
        9. Pseudo inverse
        10. Time for action – computing the pseudo inverse of a matrix
          1. What just happened?
        11. Determinants
        12. Time for action – calculating the determinant of a matrix
          1. What just happened?
        13. Fast Fourier transform
        14. Time for action – calculating the Fourier transform
          1. What just happened?
        15. Shifting
        16. Time for action – shifting frequencies
          1. What just happened?
        17. Random numbers
        18. Time for action – gambling with the binomial
          1. What just happened?
        19. Hypergeometric distribution
        20. Time for action – simulating a game show
          1. What just happened?
        21. Continuous distributions
        22. Time for action – drawing a normal distribution
          1. What just happened?
        23. Lognormal distribution
        24. Time for action – drawing the lognormal distribution
          1. What just happened?
        25. Summary
      14. 7. Peeking Into Special Routines
        1. Sorting
        2. Time for action – sorting lexically
          1. What just happened?
          2. Have a go hero – trying a different sort order
        3. Complex numbers
        4. Time for action – sorting complex numbers
          1. What just happened?
          2. Pop quiz – generating random numbers
        5. Searching
        6. Time for action – using searchsorted
          1. What just happened?
        7. Array elements extraction
        8. Time for action – extracting elements from an array
          1. What just happened?
        9. Financial functions
        10. Time for action – determining future value
          1. What just happened?
        11. Present value
        12. Time for action – getting the present value
          1. What just happened?
        13. Net present value
        14. Time for action – calculating the net present value
          1. What just happened?
        15. Internal rate of return
        16. Time for action – determining the internal rate of return
          1. What just happened?
        17. Periodic payments
        18. Time for action – calculating the periodic payments
          1. What just happened?
        19. Number of payments
        20. Time for action – determining the number of periodic payments
          1. What just happened?
        21. Interest rate
        22. Time for action – figuring out the rate
          1. What just happened?
        23. Window functions
        24. Time for action – plotting the Bartlett window
          1. What just happened?
        25. Blackman window
        26. Time for action – smoothing stock prices with the Blackman window
          1. What just happened?
        27. Hamming window
        28. Time for action – plotting the Hamming window
          1. What just happened?
        29. Kaiser window
        30. Time for action – plotting the Kaiser window
          1. What just happened?
        31. Special mathematical functions
        32. Time for action – plotting the modified Bessel function
          1. What just happened?
        33. Sinc
        34. Time for action - plotting the sinc function
          1. What just happened?
        35. Summary
      15. 8. Assure Quality with Testing
        1. Assert functions
        2. Time for action – asserting almost equal
          1. What just happened?
          2. Pop quiz – specifying decimal precision
        3. Approximately equal arrays
        4. Time for action – asserting approximately equal
          1. What just happened?
        5. Almost equal arrays
        6. Time for action – asserting arrays almost equal
          1. What just happened?
          2. Have a go hero – comparing array with different shapes
        7. Equal arrays
        8. Time for action – comparing arrays
          1. What just happened?
        9. Ordering arrays
        10. Time for action – checking the array order
          1. What just happened?
        11. Objects comparison
        12. Time for action – comparing objects
          1. What just happened?
        13. String comparison
        14. Time for action – comparing strings
          1. What just happened?
        15. Floating point comparisons
        16. Time for action – comparing with assert_array_almost_equal_nulp
          1. What just happened?
        17. Comparison of floats with more ULPs
        18. Time for action – comparing using maxulp of 2
          1. What just happened?
        19. Summary
      16. 9. Plotting with Matplotlib
        1. Simple plots
        2. Time for action – plotting a polynomial function
          1. What just happened?
          2. Pop quiz – doing the thing
        3. Plot format string
        4. Time for action – plotting a polynomial and its derivative
          1. What just happened?
        5. Subplots
        6. Time for action – plotting a polynomial and its derivatives
          1. What just happened?
        7. Finance
        8. Time for action – plotting a year's worth of stock quotes
          1. What just happened?
        9. Histograms
        10. Time for action – charting stock price distributions
          1. What just happened?
          2. Have a go hero – drawing a bell curve
        11. Logarithmic plots
        12. Time for action – plotting stock volume
          1. What just happened?
        13. Scatter plots
        14. Time for action – plotting price and volume returns with scatter plot
          1. What just happened?
        15. Fill between
        16. Time for action – shading plot regions based on a condition
          1. What just happened?
        17. Legend and annotations
        18. Time for action – using legend and annotations
          1. What just happened?
        19. Summary
      17. 10. When NumPy is Not Enough: SciPy and Beyond
        1. Matlab and Octave
        2. Time for action – saving and loading a .mat file
          1. What just happened?
          2. Pop quiz – loading .mat files
        3. Statistics
        4. Time for action – analyzing random values
          1. What just happened?
          2. Have a go hero – improving the data generation
        5. Samples comparison and SciKits
        6. Time for action – comparing stock log returns
          1. What just happened?
        7. Signal processing
        8. Time for action – detecting a trend in QQQ
          1. What just happened?
        9. Fourier analysis
        10. Time for action – filtering a detrended signal
          1. What just happened?
        11. Optimization
        12. Time for action – fitting to a sine
          1. What just happened?
        13. Numerical integration
        14. Time for action – calculating the Gaussian integral
          1. What just happened?
        15. Interpolation
        16. Time for action – interpolating in one dimension
          1. What just happened?
        17. Image processing
        18. Time for action – manipulating Lena
          1. What just happened?
        19. Summary
      18. A. Pop Quiz Answers
        1. Chapter 1, NumPy Quick Start
        2. Chapter 2, Beginning with NumPy Fundamentals
        3. Chapter 3, Get into Terms with Commonly Used Functions
        4. Chapter 4, Convenience Functions for Your Convenience
        5. Chapter 5, Working with Matrices and ufuncs
        6. Chapter 6, Move Further with NumPy Modules
        7. Chapter 7, Peeking into Special Routines
        8. Chapter 8, Assured Quality with Testing
        9. Chapter 9, Plotting with Matplotlib
        10. Chapter 10, When NumPy is not enough SciPy and Beyond
      19. Index