You are previewing NumPy Cookbook - Second Edition.
O'Reilly logo
NumPy Cookbook - Second Edition

Book Description

Over 90 fascinating recipes to learn and perform mathematical, scientific, and engineering Python computations with NumPy

In Detail

NumPy has the ability to give you speed and high productivity. High performance calculations can be done easily with clean and efficient code, and it allows you to execute complex algebraic and mathematical computations in no time.

This book will give you a solid foundation in NumPy arrays and universal functions. Starting with the installation and configuration of IPython, you'll learn about advanced indexing and array concepts along with commonly used yet effective functions. You will then cover practical concepts such as image processing, special arrays, and universal functions. You will also learn about plotting with Matplotlib and the related SciPy project with the help of examples. At the end of the book, you will study how to explore atmospheric pressure and its related techniques. By the time you finish this book, you'll be able to write clean and fast code with NumPy.

What You Will Learn

  • Learn advanced indexing and linear algebra

  • Deal with missing stock price data using masked arrays

  • Explore everything you need to know about image processing

  • Dive into broadcasting and histograms

  • Profile NumPy code and visualize the results

  • Speed up your code with Cython

  • Use universal functions and interoperability features

  • Analyze your performance using Quality Assurance

  • Learn about exploratory and predictive data analysis with NumPy

  • 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.

    Table of Contents

    1. NumPy Cookbook Second Edition
      1. Table of Contents
      2. NumPy Cookbook Second Edition
      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 this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Winding Along with IPython
        1. Introduction
        2. Installing IPython
          1. How to do it...
          2. How it works...
          3. See also
        3. Using IPython as a shell
          1. How to do it...
          2. How it works...
          3. See also
        4. Reading manual pages
          1. How to do it...
          2. How it works...
        5. Installing matplotlib
          1. How to do it...
          2. See also
        6. Running an IPython notebook
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Exporting an IPython notebook
          1. How to do it...
        8. Importing a web notebook
          1. How to do it...
        9. Configuring a notebook server
          1. How to do it...
          2. How it works...
          3. See also
        10. Exploring the SymPy profile
          1. Getting ready
          2. How to do it...
          3. See also
      9. 2. Advanced Indexing and Array Concepts
        1. Introduction
        2. Installing SciPy
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Installing PIL
          1. How to do it...
          2. See also
        4. Resizing images
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Creating views and copies
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        6. Flipping Lena
          1. How to do it...
          2. See also
        7. Fancy indexing
          1. How to do it...
          2. How it works...
          3. See also
        8. Indexing with a list of locations
          1. How to do it...
          2. See also
        9. Indexing with Booleans
          1. How to do it...
          2. How it works...
          3. See also
        10. Stride tricks for Sudoku
          1. How to do it...
          2. How it works...
          3. See also
        11. Broadcasting arrays
          1. How to do it...
          2. See also
      10. 3. Getting to Grips with Commonly Used Functions
        1. Introduction
        2. Summing Fibonacci numbers
          1. How to do it...
          2. How it works...
          3. See also
        3. Finding prime factors
          1. How to do it...
          2. How it works...
        4. Finding palindromic numbers
          1. How to do it...
          2. How it works...
          3. There's more...
        5. The steady state vector
          1. How to do it...
          2. How it works...
          3. See also
        6. Discovering a power law
          1. How to do it...
          2. How it works...
          3. See also
        7. Trading periodically on dips
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Simulating trading at random
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Sieving integers with the Sieve of Eratosthenes
          1. How to do it...
      11. 4. Connecting NumPy with the Rest of the World
        1. Introduction
        2. Using the buffer protocol
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Using the array interface
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Exchanging data with MATLAB and Octave
          1. Getting ready
          2. How to do it...
          3. See also
        5. Installing RPy2
          1. How to do it...
          2. See also
        6. Interfacing with R
          1. Getting ready
          2. How to do it...
          3. See also
        7. Installing JPype
          1. How to do it...
        8. Sending a NumPy array to JPype
          1. How to do it...
          2. How it works...
          3. See also
        9. Installing Google App Engine
          1. How to do it...
        10. Deploying the NumPy code on the Google Cloud
          1. How to do it...
          2. How it works...
        11. Running the NumPy code in a PythonAnywhere web console
          1. How to do it...
          2. How it works...
      12. 5. Audio and Image Processing
        1. Introduction
        2. Loading images into memory maps
          1. Getting ready
          2. How to do it...
            1. How it works...
            2. See also
        3. Combining images
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        4. Blurring images
          1. How to do it...
          2. How it works...
          3. See also
        5. Repeating audio fragments
          1. How to do it...
          2. How it works...
          3. See also
        6. Generating sounds
          1. How to do it...
          2. How it works...
          3. See also
        7. Designing an audio filter
          1. How to do it...
          2. How it works...
        8. Edge detection with the Sobel filter
          1. How to do it...
          2. How it works...
      13. 6. Special Arrays and Universal Functions
        1. Introduction
        2. Creating a universal function
          1. How to do it...
          2. How it works...
          3. See also
        3. Finding Pythagorean triples
          1. How to do it...
          2. How it works...
          3. See also
        4. Performing string operations with chararray
          1. How to do it...
          2. How it works...
          3. See also
        5. Creating a masked array
          1. How to do it...
          2. How it works...
          3. See also
        6. Ignoring negative and extreme values
          1. How to do it...
          2. How it works...
          3. See also
        7. Creating a scores table with a recarray function
          1. How to do it...
          2. How it works...
          3. See also
      14. 7. Profiling and Debugging
        1. Introduction
        2. Profiling with timeit
          1. How to do it...
          2. How it works...
          3. See also
        3. Profiling with IPython
          1. How to do it...
          2. How it works...
          3. See also
        4. Installing line_profiler
          1. Getting ready
          2. How to do it...
          3. See also
        5. Profiling code with line_profiler
          1. How to do it...
          2. How it works...
          3. See also
        6. Profiling code with the cProfile extension
          1. How to do it...
          2. See also
        7. Debugging with IPython
          1. How to do it...
          2. How it works...
          3. See also
        8. Debugging with PuDB
          1. How to do it...
          2. See also
      15. 8. Quality Assurance
        1. Introduction
        2. Installing Pyflakes
          1. Getting ready
          2. How to do it...
          3. See also
        3. Performing static analysis with Pyflakes
          1. How to do it...
          2. How it works...
        4. Analyzing code with Pylint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Performing static analysis with Pychecker
          1. How to do it...
        6. Testing code with docstrings
          1. How to do it...
          2. How it works...
          3. See also
        7. Writing unit tests
          1. How to do it...
          2. How it works...
        8. Testing code with mocks
          1. How to do it...
          2. How it works...
          3. See also
        9. Testing the BDD way
          1. How to do it…
          2. How it works...
          3. See also
      16. 9. Speeding Up Code with Cython
        1. Introduction
        2. Installing Cython
          1. How to do it...
          2. See also
        3. Building a Hello World program
          1. How to do it...
          2. How it works...
          3. See also
        4. Using Cython with NumPy
          1. How to do it...
          2. How it works...
          3. See also
        5. Calling C functions
          1. How to do it...
          2. How it works...
          3. See also
        6. Profiling the Cython code
          1. How to do it...
          2. How it works...
          3. See also
        7. Approximating factorials with Cython
          1. How to do it...
          2. How it works...
          3. See also
      17. 10. Fun with Scikits
        1. Introduction
        2. Installing scikit-learn
          1. Getting ready
          2. How to do it...
        3. Loading an example dataset
          1. How to do it...
        4. Clustering Dow Jones stocks with scikits-learn
          1. How to do it...
          2. How it works...
          3. See also
        5. Installing statsmodels
          1. How to do it...
        6. Performing a normality test with statsmodels
          1. How to do it...
          2. How it works...
        7. Installing scikit-image
          1. How to do it...
        8. Detecting corners
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        9. Detecting edges
          1. How to do it...
          2. See also
        10. Installing pandas
          1. How to do it...
          2. See also
        11. Estimating correlation of stock returns with pandas
          1. How to do it...
          2. How it works...
          3. See also
        12. Loading data as pandas objects from statsmodels
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        13. Resampling time series data
          1. How to do it...
          2. How it works...
          3. See also
      18. 11. Latest and Greatest NumPy
        1. Introduction
        2. Fancy indexing in place for ufuncs with the at() method
          1. How to do it...
          2. See also
        3. Partial sorting via selection for fast median with the partition() function
          1. How to do it...
          2. How it works...
          3. See also
        4. Skipping NaNs with the nanmean(), nanvar(), and nanstd() functions
          1. How to do it...
          2. How it works...
          3. See also
        5. Creating value initialized arrays with the full() and full_like() functions
          1. How to do it...
          2. How it works...
        6. Random sampling with numpy.random.choice()
          1. How to do it...
          2. How it works...
          3. See also
        7. Using the datetime64 type and related API
          1. How to do it...
          2. How it works...
          3. See also
      19. 12. Exploratory and Predictive Data Analysis with NumPy
        1. Introduction
        2. Exploring atmospheric pressure
          1. Getting ready
          2. How to do it...
          3. See also
        3. Exploring the day-to-day pressure range
          1. How to do it...
          2. How it works...
          3. See also
        4. Studying annual atmospheric pressure averages
          1. How to do it...
          2. How it works...
          3. See also
        5. Analyzing maximum visibility
          1. How to do it...
          2. How it works...
          3. See also
        6. Predicting pressure with an autoregressive model
          1. How to do it...
          2. How it works...
          3. See also
        7. Predicting pressure with a moving average model
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        8. Studying intrayear average pressure
          1. How to do it...
          2. How it works...
          3. See also
        9. Studying extreme values of atmospheric pressure
          1. How to do it...
          2. How it works...
          3. See also
      20. Index