NumPy User Guide - SciPy

NumPy User Guide

Release 1.5.1 Written by the NumPy community

November 18, 2010

CONTENTS

1 Introduction

3

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

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

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

2 Numpy basics

9

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

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

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

2.4 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.5 Broadcasting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

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

2.7 Structured arrays (aka "Record arrays") . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

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

3 Performance

43

4 Miscellaneous

45

4.1 IEEE 754 Floating Point Special Values: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

4.2 Examples: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

4.3 Interfacing to C: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

4.4 Interfacing to Fortran: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.5 Interfacing to C++: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4.6 Methods vs. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

5 Using Numpy C-API

51

5.1 How to extend NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

5.2 Using Python as glue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

5.3 Beyond the Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

Python Module Index

87

Index

89

i

ii

NumPy User Guide, Release 1.5.1

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