NumPy 1.5. open source. Beginner's Guide. v g I. performance, Python based free open source NumPy. An action-packed guide for the easy-to-use, high

Similar documents
2 Getting Started with Numerical Computations in Python

A Glimpse at Scipy FOSSEE. June Abstract This document shows a glimpse of the features of Scipy that will be explored during this course.

Lectures about Python, useful both for beginners and experts, can be found at (

Python & Numpy A tutorial

ECE521 W17 Tutorial 1. Renjie Liao & Min Bai

Adaptive Filtering. Squares. Alexander D. Poularikas. Fundamentals of. Least Mean. with MATLABR. University of Alabama, Huntsville, AL.

Applied Linear Algebra in Geoscience Using MATLAB

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

Outline Python, Numpy, and Matplotlib Making Models with Polynomials Making Models with Monte Carlo Error, Accuracy and Convergence Floating Point Mod

Analyzing the Earth Using Remote Sensing

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Contents. Preface to the Third Edition (2007) Preface to the Second Edition (1992) Preface to the First Edition (1985) License and Legal Information

I. Numerical Computing

Image Processing in Numpy

Applied Linear Algebra in Geoscience Using MATLAB

Contents. Acknowledgments

WILEY. Differential Equations with MATLAB (Third Edition) Brian R. Hunt Ronald L. Lipsman John E. Osborn Jonathan M. Rosenberg

Linear Algebra in Numerical Methods. Lecture on linear algebra MATLAB/Octave works well with linear algebra

Algorithms for Uncertainty Quantification

College Algebra Poudre School District Pacing Overview

Math 307 Learning Goals. March 23, 2010

L3: Review of linear algebra and MATLAB

Introduction to Python

Skriptsprachen. Numpy und Scipy. Kai Dührkop. Lehrstuhl fuer Bioinformatik Friedrich-Schiller-Universitaet Jena

Coding the Matrix Index - Version 0

NUMERICAL METHODS USING MATLAB

Identify the graph of a function, and obtain information from or about the graph of a function.

THE PYTHAGOREAN THEOREM

ENVIRONMENTAL DATA ANALYSIS WILLIAM MENKE JOSHUA MENKE WITH MATLAB COPYRIGHT 2011 BY ELSEVIER, INC. ALL RIGHTS RESERVED.

Companion. Jeffrey E. Jones

Preface to Second Edition... vii. Preface to First Edition...

Linear Algebra and Probability

pyoptfem Documentation

Contents. UNIT 1 Descriptive Statistics 1. vii. Preface Summary of Goals for This Text

Linear Transformations

Computational Methods for Nonlinear Systems

1 Overview of Simulink. 2 State-space equations

Preface. Figures Figures appearing in the text were prepared using MATLAB R. For product information, please contact:

Background Mathematics (2/2) 1. David Barber

Syllabus for IMGS-616 Fourier Methods in Imaging (RIT #11857) Week 1: 8/26, 8/28 Week 2: 9/2, 9/4

Introduction to Python

ECE 5615/4615 Computer Project

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology

Spiral Review Probability, Enter Your Grade Online Quiz - Probability Pascal's Triangle, Enter Your Grade

age for ^^Undergraduates Gregory V. Bard Providence, Rhode Island AMERICAN MATHEMATICAL SOCIETY

Course Name: Digital Signal Processing Course Code: EE 605A Credit: 3

Name: INSERT YOUR NAME HERE. Due to dropbox by 6pm PDT, Wednesday, December 14, 2011

IDL Advanced Math & Stats Module

DATA SCIENCE SIMPLIFIED USING ARCGIS API FOR PYTHON

TEMScripts Real-time Crystallography Manual. TEMScripts LLC. Last updated: 11/4/2016

MATHEMATICAL OBJECTS in

A Matrix Operator in APL Bob Smith Sudley Place Software Originally Written 30 Jul 2017 Updated 10 Sep 2017 PRELIMINARY

correlated to the Washington D.C. Public Schools Learning Standards Algebra II

Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3

Practical Information

Magnetotellurics Impedance Tensor Tools (MITT)

1 Number Systems and Errors 1

QR 2: Least Squares and Computing Eigenvalues

Computational Methods for Nonlinear Systems

Numpy. Luis Pedro Coelho. October 22, Programming for Scientists. Luis Pedro Coelho (Programming for Scientists) Numpy October 22, 2012 (1 / 26)

PySaxs A Python module and GUI for SAXS data treatment

ESCI 386 Scientific Programming, Analysis and Visualization with Python. Lesson 18 - Linear Algebra

A Brief Introduction To. GRTensor. On MAPLE Platform. A write-up for the presentation delivered on the same topic as a part of the course PHYS 601

Scikit-learn. scikit. Machine learning for the small and the many Gaël Varoquaux. machine learning in Python

TRIGONOMETRY AND PRECALCULUS CURRICULUM Course 17008

Third Edition. William H. Press. Raymer Chair in Computer Sciences and Integrative Biology The University of Texas at Austin. Saul A.

Remark 1 By definition, an eigenvector must be a nonzero vector, but eigenvalue could be zero.

1. Quantization Signal to Noise Ratio (SNR).

which implies that we can take solutions which are simultaneous eigen functions of

Numerical Methods for Engineers. and Scientists. Applications using MATLAB. An Introduction with. Vish- Subramaniam. Third Edition. Amos Gilat.

xvi xxiii xxvi Construction of the Real Line 2 Is Every Real Number Rational? 3 Problems Algebra of the Real Numbers 7

SVD and Image Compression

Mathematics for Engineers and Scientists

Math 307 Learning Goals

WA State Common Core Standards - Mathematics

Ref:GIS Math G 11 C.D

SLO to ILO Alignment Reports

Scientific Computing: An Introductory Survey

IAST Documentation. Release Cory M. Simon

Lab 4: Working with arrays and eigenvalues

Parallelization of the FE-solver ICONA

Abstract Interpretation with Higher-Dimensional Ellipsoids and Conic Extrapolation

DFT & Fast Fourier Transform PART-A. 7. Calculate the number of multiplications needed in the calculation of DFT and FFT with 64 point sequence.

Prentice Hall CME Project, Algebra

Creative Data Mining

Chapter 2: The Fourier Transform

Definition of the Drazin Inverse

Quantile Textbook Report

Mathematics (MAT) MAT 051 Pre-Algebra. 4 Hours. Prerequisites: None. 4 hours weekly (4-0)

Root Finding and Optimization

Algebra vocabulary CARD SETS Frame Clip Art by Pixels & Ice Cream

MODELS USING MATRICES WITH PYTHON

Neural Networks Teaser

MA3025 Course Prerequisites

Applied Linear Algebra

FILTERING IN THE FREQUENCY DOMAIN

Introduction to Techniques for Counting

Instructional Calendar Accelerated Integrated Precalculus. Chapter 1 Sections and 1.6. Section 1.4. Section 1.5

COURSE OF STUDY MATHEMATICS

B553 Lecture 5: Matrix Algebra Review

Transcription:

NumPy 1.5 Beginner's Guide An actionpacked guide for the easytouse, high performance, Python based free open source NumPy mathematical library using realworld examples Ivan Idris.; 'J 'A,, v g I open source I community experience distilled PUBLISHING BIRMINGHAM MUMBAI

installing installing installing creating Preface 1 Chapter 1: NumPy Quick Start 9 Python 9 Python on different operating systems 10 Windows 10 installing NumPy on Windows 11 Linux 13 installing NumPy on Linux 13 Mac OS X 14 NumPy on Mac OS X with a GUI installer 14 NumPy with MacPorts or Fink 16 Building from source 16 Vectors 16 adding vectors 17 IPython an interactive shell 20 Online resources and help 23 Summary 24 Chapter 2: Beginning with NumPy Fundamentals 25 NumPy array object 26 creating a multidimensional array 27 Selecting elements 28 NumPy numerical types 28 Data type objects 30 Character codes 30 dtype constructors 31 dtype attributes 32 a record data type 32

splitting reading calculating doing analyzing calculating enveloping predicting Onedimensional slicing and indexing 33 slicing and indexing multidimensional arrays 34 manipulating array shapes 36 Stacking 38 stacking arrays 38 Splitting 41 arrays 41 Array attributes 43 converting arrays 46 Summary 47 Chapter 3: Get into Terms with Commonly Used Functions 49 File I/O 49 and writing files 50 Identity matrix creation 50 CSV files 50 loading from CSV files 51 Volume weighted average price 51 volume weighted average price 52 The mean function 52 Time weighted average price 52 Value range 53 finding highest and lowest values 53 Statistics 54 simple statistics 54 Stock returns 56 stock returns 57 Dates 58 dealing with dates 58 Weekly summary 61 Time for action summarizing data 61 Average true range 65 the average true range 65 Simple moving average 66 computing the simple moving average 67 Exponential moving average 68 calcu lating the exponential moving average 69 Bollinger bands 70 with Bollinger bands 71 Linear model 72 price with a linear model 73

drawing avoiding computing Trend lines 74 trend lines 75 Methods of ndarray 78 clipping and compressing arrays 78 Factorial 79 calculating the factorial 79 Summary 80 Chapter 4: Convenience Functions for Your Convenience 81 Correlation 82 trading correlated pairs 82 Polynomials 85 fitting to polynomials 85 Onbalance volume 88 balancing volume 88 The mode 90 determining the mode of stock returns 90 Simulation 93 loops with vectorize 93 Smoothing 95 smoothing with the hanning function 95 Summary 98 Chapter 5: Working with Matrices and ufuncs 99_ Matrices 99 creating matrices 100 Creating a matrix from other matrices 101 creating a matrix from other matrices 101 Universal functions 102 creating universal function 102 Universal function methods 103 applying the ufunc methods on add 104 Arithmetic functions 105 dividing arrays 106 Modulo operation 107 computing the modulo 107 Fibonacci numbers 108 Fibonacci numbers 108 Lissajous curves 109 drawing Lissajous curves 110 Square waves 111 drawing a square wave 111 Hill

decomposing computing shifting gambling simulating drawing drawing sorting sorting extracting Table ofcontents Sawtooth and triangle waves 112 drawing sawtooth and triangle waves 113 Bitwise and comparison functions 114 twiddling bits 114 Summary 116 Chapter 6: Move Further with NumPy Modules 117 Linear algebra 117 inverting matrices 117 Solving linear systems 119 solving a linear system 119 Finding eigenvalues and eigenvectors 120 determining eigenvalues and eigenvectors 120 Singular value decomposition 121 a matrix 122 Pseudo inverse 123 the pseudo inverse of a matrix 123 Determinants 124 calculating the determinant of a matrix 124 Fast Fourier transform 124 calculating the Fourier transform 125 Shifting 126 frequencies 126 Random numbers 127 with the binomial 127 Hypergeometric distribution 129 a game show 129 Continuous distributions 130 a normal distribution 130 Lognormal distribution 131 the lognormal distribution 132 Summary 133 Chapter 7: Peeking Into Special Routines 135 Sorting 135 lexically 136 Complex numbers 137 complex numbers 137 Searching 138 using searchsorted 138 Array elements extraction 139 elements from an array 139 llv]

determining determining plotting plotting asserting comparing Financial functions 139 future value 140 Present value 140 getting the present value 140 Net present value 141 calculating the net present value 141 Internal rate of return 141 determining the internal rate of return 142 Periodic payments 142 calculating the periodic payments 142 Number of payments 143 the number of periodic payments 143 Interest rate 143 figuring out the rate 143 Window functions 144 plotting the Bartlett window 144 Blackman window 145 Time for action smoothing stock prices with the Blackman window 145 Hamming window 146 the Hamming window 147 Kaiser window 148 the Kaiser window 148 Special mathematical functions 149 plotting the modified Bessel function 149 Sine 150 plotting the sine function 150 Summary 151 Chapter 8: Assure Quality with Testing 153 Assert functions 153 asserting almost equal 154 Approximately equal arrays 155 approximately equal 155 Almost equal arrays 156 asserting arrays almost equal 156 Equal arrays 157 comparing arrays 157 Ordering arrays 158 checking the array order 158 Objects comparison 159 objects 159

plotting saving detecting String comparison 160 comparing strings 160 Floating point comparisons 161 comparing with assert_array_almost_equal_nulp 161 Comparison of floats with more ULPs 162 comparing using maxulp of 2 162 Summary 163 Chapter 9: Plotting with Matplotlib 165 Simple plots 165 plotting a polynomial function 166 Plot format string 167 Time for action plotting a polynomial and its derivative 167 Subplots 168 a polynomial and its derivatives 168 Finance 170 plotting a year's worth of stock quotes 171 Histograms 172 charting stock price distributions 173 Logarithmic plots 174 plotting stock volume 174 Scatter plots 175 plotting price and volume returns with scatter plot 175 Fill between 176 shading plot regions based on a condition 176 Legend and annotations 178 using legend and annotations 178 Summary 180 Chapter 10: When NumPy is Not Enough: SciPy and Beyond 181 Matlab and Octave 181 and loading a.mat file 182 Statistics 183 analyzing random values 183 Samples comparison and SciKits 185 comparing stock log returns 185 Signal processing 187 a trend in QQQ 187 Fourier analysis 189

interpolating filtering a detrended signal 189 Optimization 191 fitting to a sine 191 Numerical integration 194 calculating the Gaussian integral 194 Interpolation 194 in one dimension 194 Image processing 196 manipulating Lena 196 Summary 197 Pop Quiz Answers 199 Chapter 1, NumPy Quick Start 199 Chapter 2, Beginning with NumPy Fundamentals 199 Chapter 3, Get into Terms with Commonly Used Functions 199 Chapter 4, Convenience Functions for Your Convenience 199 Chapter 5, Working with Matrices and ufuncs 200 Chapter 6, Move Further with NumPy Modules 200 Chapter 7, Peeking into Special Routines 200 Chapter 8, Assured Quality with Testing 200 Chapter 9, Plotting with Matplotlib 200 Chapter 10, When NumPy is not enough SciPy and Beyond 200 Index 201 Iviil