NumPy User Guide - SciPy

NumPy User Guide

Release 1.8.0

Written by the NumPy community

November 10, 2013

CONTENTS

1

Introduction

1.1 What is NumPy? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2 Building and installing NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3 How to find documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

Numpy basics

2.1 Data types . . . . . . . . . . . . . . .

2.2 Array creation . . . . . . . . . . . . .

2.3 I/O with Numpy . . . . . . . . . . . .

2.4 Indexing . . . . . . . . . . . . . . . .

2.5 Broadcasting . . . . . . . . . . . . . .

2.6 Byte-swapping . . . . . . . . . . . . .

2.7 Structured arrays (aka ¡°Record arrays¡±)

2.8 Subclassing ndarray . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

3

4

7

9

9

11

13

20

26

29

31

34

3

Performance

4

Miscellaneous

4.1 IEEE 754 Floating Point Special Values: .

4.2 How numpy handles numerical exceptions:

4.3 Examples: . . . . . . . . . . . . . . . . .

4.4 Interfacing to C: . . . . . . . . . . . . . .

4.5 Interfacing to Fortran: . . . . . . . . . . .

4.6 Interfacing to C++: . . . . . . . . . . . . .

4.7 Methods vs. Functions . . . . . . . . . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

45

45

46

46

46

48

49

49

Using Numpy C-API

5.1 How to extend NumPy .

5.2 Using Python as glue . .

5.3 Writing your own ufunc

5.4 Beyond the Basics . . .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

51

51

58

78

96

5

Index

43

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

105

i

ii

NumPy User Guide, Release 1.8.0

This guide is intended as an introductory overview of NumPy and explains how to install and make use of the most

important features of NumPy. For detailed reference documentation of the functions and classes contained in the

package, see the reference.

Warning: This ¡°User Guide¡± is still a work in progress; some of the material is not organized, and several aspects

of NumPy are not yet covered sufficient detail. We are an open source community continually working to improve

the documentation and eagerly encourage interested parties to contribute. For information on how to do so, please

visit the NumPy doc wiki.

More documentation for NumPy can be found on the website.

Thanks!

CONTENTS

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download