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

Book Description

Boost your scientific and analytic capabilities in no time at all by discovering how to build real-world applications with NumPy

About This Book

  • Optimize your Python scripts with powerful NumPy modules

  • Explore the vast opportunities to build outstanding scientific/ analytical modules by yourself

  • Packed with rich examples to help you master NumPy arrays and universal functions

  • Who This Book Is For

    If you are an experienced Python developer who intends to drive your numerical and scientific applications with NumPy, this book is for you. Prior experience or knowledge of working with the Python language is required.

    What You Will Learn

  • Manipulate the key attributes and universal functions of NumPy

  • Utilize matrix and mathematical computation using linear algebra modules

  • Implement regression and curve fitting for models

  • Perform time frequency / spectral density analysis using the Fourier Transform modules

  • Collate with the distutils and setuptools modules used by other Python libraries

  • Establish Cython with NumPy arrays

  • Write extension modules for NumPy code using the C API

  • Build sophisticated data structures using NumPy array with libraries such as Panda and Scikits

  • 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 gives you both the speed and high productivity you need.

    This book will walk you through NumPy using clear, step-by-step examples and just the right amount of theory. We will guide you through wider applications of NumPy in scientific computing and will then focus 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; solving linear systems of equations, interpolation, extrapolation, regression, and curve fitting; and evaluating integrals and derivatives. We will also introduce you to using Cython with NumPy arrays and writing extension modules for NumPy code using the C API. This book will give you exposure to the vast NumPy library and help you build efficient, high-speed programs using a wide range of mathematical features.

    Style and approach

    This quick guide will help you get to grips with the nitty-gritties of NumPy using with practical programming examples. Each topic is explained in both theoretical and practical ways with hands-on examples providing you efficient way of learning and adequate knowledge to support your professional work.

    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 If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. NumPy Essentials
      1. NumPy Essentials
      2. Credits
      3. About the Authors
      4. About the Reviewers
        1. Why subscribe?
        2. Free access for Packt account holders
      6. 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
      7. 1. An Introduction to NumPy
        1. The scientific Python stack
        2. The need for NumPy arrays
          1. Representing of matrices and vectors
          2. Efficiency
          3. Ease of development
        3. NumPy in Academia and Industry
        4. Code conventions used in the book
        5. Installation requirements
          1. Using Python distributions
          2. Using Python package managers
          3. Using native package managers
        6. Summary
      8. 2. The NumPy ndarray Object
        1. Getting started with numpy.ndarray
        2. Array indexing and slicing
        3. Memory layout of ndarray
        4. Views and copies
        5. Creating arrays
          1. Creating arrays from lists
          2. Creating random arrays
          3. Other arrays
        6. Array data types
        7. Summary
      9. 3. Using NumPy Arrays
        1. Vectorized operations
        2. Universal functions (ufuncs)
          1. Getting started with basic ufuncs
          2. Working with more advanced ufuncs
        3. Broadcasting and shape manipulation
          1. Broadcasting rules
          2. Reshaping NumPy Arrays
          3. Vector stacking
        4. A boolean mask
        5. Helper functions
        6. Summary
      10. 4. NumPy Core and Libs Submodules
        1. Introducing strides
        2. Structured arrays
          1. Dates and time in NumPy
          2. File I/O and NumPy
        3. Summary
      11. 5. Linear Algebra in NumPy
        1. The matrix class
        2. Linear algebra in NumPy
        3. Decomposition
        4. Polynomial mathematics
        5. Application - regression and curve fitting
        6. Summary
      12. 6. Fourier Analysis in NumPy
        1. Before we start
        2. Signal processing
        3. Fourier analysis
        4. Fourier transform application
        5. Summary
      13. 7. Building and Distributing NumPy Code
        1. Introducing Distutils and setuptools
        2. Preparing the tools
        3. Building the first working distribution
          1. Adding NumPy and non-Python source code
        4. Testing your package
        5. Distributing your application
        6. Summary
      14. 8. Speeding Up NumPy with Cython
        1. The first step toward optimizing code
        2. Setting up Cython
        3. Hello world in Cython
        4. Multithreaded code
        5. NumPy and Cython
        6. Summary
      15. 9. Introduction to the NumPy C-API
        1. The Python and NumPy C-API
        2. The basic structure of an extension module
          1. The header segment
          2. The initialization segment
          3. The method structure array
          4. The implementation segment
        3. Creating an array squared function using Python C-API
        4. Creating an array squared function using NumPy C-API
        5. Building and installing the extension module
        6. Summary
      16. 10. Further Reading
        1. pandas
        2. scikit-learn
        3. netCDF4
        4. SciPy
        5. Summary