SciPy Recipes

Author: Kishore Ayyadevara   Luiz Felipe Martins   Ruben Oliva Ramos   Tomas Oliva   Ke Wu  

Publisher: Packt Publishing‎

Publication year: 2017

E-ISBN: 9781788295819

P-ISBN(Paperback): 89543100238630

Subject: TP312 程序语言、算法语言

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

SciPy Recipes

Chapter

Preface

Chapter 1: Getting to Know the Tools

Introduction

Installing Anaconda on Windows

How to do it...

Installing Anaconda on macOS

How to do it...

Installing Anaconda on Linux

How to do it...

Checking the Anaconda installation

How to do it...

Installing SciPy from a binary distribution on Windows

How to do it...

Installing Python

Installing the SciPy stack

Installing SciPy from a binary distribution on macOS

How to do it...

Installing the Xcode command-line tools

Installing Homebrew

Installing Python 3

Installing the SciPy stack

Installing SciPy from source on Linux

How to do it...

Installing Python 3

Installing the SciPy stack

Installing optional packages with conda

Getting ready

How to do it...

Installing packages with pip

How to do it...

Setting up a virtual environment with conda

Getting ready

How to do it...

Creating a virtual environment for development with conda 

Getting ready

How to do it...

Creating a conda environment with a different version of a package

Getting ready

How to do it...

Using conda environments to run different versions of Python

Getting ready

How to do it...

Creating virtual environments with venv

How to do it...

Running SciPy in a script

Getting ready

How to do it...

Running SciPy in Jupyter

Getting ready

How to do it...

Running SciPy in Spyder

Getting ready

How to do it...

Running SciPy in PyCharm

Getting started

How to do it...

Chapter 2: Getting Started with NumPy

Introduction

Creating NumPy arrays

How to do it…

Creating an array from a list

Specifying the data type for elements in an array

Creating an empty array with a given shape

Creating arrays of zeros and ones with a single value

Creating arrays with equally spaced values

Creating an array by repeating elements

Creating an array by tiling another array

Creating an array with the same shape as another array

Using object arrays to store heterogeneous data

See also

Querying and changing the shape of an array

How to do it...

Storing and retrieving NumPy arrays

How to do it...

Storing a NumPy array in text format

Storing a NumPy array in CSV format

Loading an array from a text file

Storing a single array in binary format

Storing several arrays in binary format

Loading arrays stored in NPY binary format

Indexing

How to do it...

Accessing sub arrays using slices

Selecting subarrays using an index list

Indexing with Boolean arrays

Operations on arrays

How to do it...

Computing a function for all elements of an array

Doing array operations

Computing matrix products

Using masked arrays to represent invalid data

How to do it...

Creating a masked array from an explicit mask

Creating a masked array from a condition

Using object arrays to store heterogeneous data

How to do it...

Defining, symbolically, a function operating on arrays

Getting ready

How to do it...

How it works...

Chapter 3: Using Matplotlib to Create Graphs

Introduction

Creating two-dimensional plots of functions and data

Getting ready

How to do it…

How it works…

Generating multiple plots in a single figure

Getting ready

How to do it…

How it works…

Setting line styles and markers

Getting ready

How to do it…

How it works…

Using different backends to display graphs

Getting ready

How to do it…

How it works…

Saving plots to disk

Getting ready

How to do it…

How it works…

Annotating graphs

Getting ready

How to do it…

How it works…

Generating histograms and box plots

Getting ready

How to do it…

How it works…

Creating three-dimensional plots

Getting ready

How to do it…

How it works…

Generating interactive displays in the Jupyter Notebook

Getting ready

How to do it…

How it works…

Object-oriented graph creation using Artist objects

Getting ready

How to do it…

How it works…

Creating a map with cartopy

Getting ready

How to do it…

How it works…

Chapter 4: Data Wrangling with pandas

Creating Series objects

Getting ready

How to do it...

How it works...

Creating DataFrame objects

Getting ready

How to do it...

How it works...

Inserting and deleting columns to a DataFrame

Getting ready

How to do it...

How it works...

Inserting and deleting rows to a DataFrame

Getting ready

How to do it...

How it works...

Selecting items by row indexes and column labels

Getting ready

How to do it...

How it works...

Selecting items by integer location

Getting ready

How to do it...

How it works...

Selecting items using mixed indexing

Getting ready

How to do it...

How it works...

Accessing, selecting, and modifying data

Getting ready

How to do it...

How it works...

Selecting rows using Boolean selection

How to do it...

Reading and storing data in different formats

Getting ready

How to do it...

Working with CSV, text/tabular, and format data

How it works...

Reading a CSV file into a DataFrame

Specifying the index column when reading a CSV file

Reading and writing data in Excel format

Reading and writing JSON files

Reading HTML data from the web

Accessing CSV data on the web

Reading and writing from/to SQL databases

Data displays employing different kinds of visual representation

Getting ready

How to do it...

How it works...

How to apply numerical functions and operations to Series and DataFrame objects

Getting ready

How to do it...

How it works...

Computing statistical functions on Series and DataFrame objects

Getting ready

How to do it...

Retrieving summary descriptive statistics

How it works...

Calculating the mean

Calculating variance and standard deviation

How to sort data in Series and DataFrame objects

Getting ready

How to do it...

How it works...

Performing merging, joins, concatenation, and grouping

Getting ready

How to do it...

How it works...

Merging data from multiple pandas objects

Chapter 5: Matrices and Linear Algebra

Introduction

Matrix operations and functions on two-dimensional arrays

How to do it…

Solving linear systems using matrices

How it works…

How to do it…

Calculating the null space of a matrix 

How to do it…

Calculating the LU decompositions of a matrix 

How to do it…

Calculating the QR decomposition of a matrix

How to do it…

Calculating the eigenvalue and eigenvector of a matrix

How to do it…

Diagonalizing a matrix

How to do it…

Calculating the Jordan form of a matrix

How to do it…

Calculating the singular value decomposition of a matrix

How to do it…

Creating a sparse matrix

How to do it…

Computations on top of a sparse matrix

How to do it…

Chapter 6: Solving Equations and Optimization

Introduction

Non-linear equations and systems

Getting ready

How to do it...

How it works...

System of equations and how to solve it

Getting ready

How to do it...

How it works...

Choosing the solver used to find the solution of equations

Getting ready

How to do it...

How it works...

Solving constrained non-linear optimization problems in several variables

Getting ready

How to do it...

How it works...

Solving one-dimensional optimization problems

Getting ready

How to do it...

How it works...

Solving multidimensional non-linear equations using the Newton-Krylov method

Getting ready

How to do it...

Solving multidimensional non-linear equations using the Anderson method

Getting ready

How to do it...

How it works...

Finding the best linear fit for a set of data

Getting ready

How to do it...

How it works ...

Doing non-linear regression for a set of data

Getting ready

How to do it...

How it works...

Regression

Getting ready

How to do it...

How it works...

Chapter 7: Constants and Special Functions

Introduction

Physical and mathematical constants available in SciPy

Getting ready...

How to do it...

Using constants in the CODATA database

Getting ready

How to do it...

Bessel functions

Getting ready...

How to do it...

Error functions

Getting ready...

How to do it...

Orthogonal polynomials functions

Getting ready...

How to do it...

Gamma function

Getting ready...

How to do it...

How it works...

The Riemann zeta function

Getting ready

How to do it...

How it works...

Airy and Bairy functions

Getting ready...

How to do it...

The Bessel and Struve functions

Getting ready...

How to do it...

How it works...

There's more

Chapter 8: Calculus, Interpolation, and Differential Equations

Introduction

Integration

Getting ready

How to do it…

How it works...

Computing integrals using the Newton-Cotes method

Computing integrals using a Gaussian quadrature

Getting ready

How to do it...

How it works...

Computing integrals with weighting functions

Getting ready

How to do it...

Computing multiple integrals

Getting ready

How to do it...

Interpolation

Getting ready

How to do it...

Computing a polynomial interpolation for a set of data points

Getting ready

How to do it…

How it works…

Univariate interpolation

Getting ready

How to do it…

Finding a cubic spline that interpolates a set of data

Getting ready

How to do it…

How it works...

Defining a B-spline for a given set of control points

Getting ready

How to do it…

How it works ...

Differentiation

Getting ready

How to do it...

How it works...

Solving a one-dimensional ordinary differential equation

Getting ready

How to do it...

How it works...

Solving a system of ordinary differential equations

Getting ready

How to do it...

How it works...

Solving differential equations and systems with parameters

Getting ready

How to do it...

How it works...

Using ode and the objected-oriented interface to solve differential equations

Getting ready

How to do it...

How it works ...

Chapter 9: Statistics and Probability

Introduction

Computing the probability mass function of a discrete random variable

Binomial discrete distribution

Multinomial discrete distribution

How to do it...

Visualizing the probability mass function

Computing the probability density function of a continuous random variable

How to do it...

Computing the cumulative distribution function for a random variable

How to do it...

Computing the values of inverse probabilities associated with a random variable

How to do it...

Computing the average, standard deviation, and higher moments of a distribution

How to do it...

Average and standard deviation of a distribution

Calculating the moments of a distribution

Computing probabilities associated with the multivariate Gaussian distribution

How to do it...

Getting started with simulation

Computing the summary statistics of a dataset

How to do it...

Chapter 10: Advanced Computations with SciPy

Discrete Fourier transforms

How to do it…

How it works…

Computing the discrete Fourier transform (DFT) of a data series using the FFT algorithm

How to do it…

How it works…

Computing the inverse DFT of a data series

How to do it…

How it works…

Computing signal construction

How to do it…

Getting started with filters

How to do it…

How it works…

Computing the DFT for two-dimensional data

How to do it…

How it works…

How to find the DFT of the derivative of a function

How to do it…

Computing the convolution of two functions

How to do it…

Mathematical imaging

How to do it…

Computing pairwise distances from a dataset, using different distance metrics

How to do it…

How to identify neighborhoods and nearest neighbors for a dataset and a given metric

How to do it…

How it works…

Nearest neighbors regression

How it works…

Index

The users who browse this book also browse


No browse record.