Leanpub Header

Skip to main content

NumPy Recipes

A practical introduction to NumPy

Minimum price

$9.99

$14.99

You pay

$14.99

Author earns

$11.99
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
82
Pages
16,350Words
About

About

About the Book

NumPy Recipes takes practical approach to the basics of NumPy

This book is primarily aimed at developers who have at least a small amount of Python experience, who wish to use the NumPy library for data analysis, machine learning, image or sound processing, or any other mathematical or scientific application. It only requires a basic understanding of Python programming.

Detailed examples show how to create arrays to optimise storage different types of information, and how to use universal functions, vectorisation, broadcasting and slicing to process data efficiently. Also contains an introduction to file i/o and data visualisation with Matplotlib.

Share this book

Author

About the Author

Martin McBride

Martin McBride is a software developer, specialising in computer graphics, sound, and mathematical programming. He has been writing code since the 1980s in a wide variety of languages from assembler through to C++, Java and Python. He writes for PythonInformer.com and is the author of Functional Programming in Python. He is interested in generative art and works on the generativepy open source project.

Contents

Table of Contents

Foreword

  1. Who is this book for?
  2. About the author
  3. Keep in touch

1 Introduction to NumPy

  1. 1.1 Installing NumPy
  2. 1.2 What is NumPy?
  3. 1.3 NumPy vs Python lists
  4. 1.4 Advantages of NumPy
  5. 1.5 NumPy universal functions
  6. 1.6 Compatibility with other libraries

2 Anatomy of a NumPy array

  1. 2.1 NumPy arrays compared to lists
  2. 2.2 Printing the characteristics of an array
  3. 2.2.1 Rank
  4. 2.2.2 Shape
  5. 2.2.3 Size
  6. 2.2.4 Data type
  7. 2.2.5 Item size
  8. 2.2.6 Data location
  9. 2.3 Array rank examples
  10. 2.4 Data types
  11. 2.4.1 Integers
  12. 2.4.2 Unsigned integers
  13. 2.4.3 Floating point values
  14. 2.4.4 Complex number formats
  15. 2.4.5 Boolean
  16. 2.4.6 List of main data types

3 Creating arrays

  1. 3.1 Creating an array of zeroes
  2. 3.2 Creating other fixed content arrays
  3. 3.3 Choosing the data type
  4. 3.4 Creating multi-dimensional arrays
  5. 3.5 Creating like arrays
  6. 3.6 Creating an array from a Python list
  7. 3.7 Controlling the type with the array function
  8. 3.8 array function anti-patterns
  9. 3.9 Creating a value series with arange
  10. 3.10 Rounding error problem with arange
  11. 3.11 Create a sequence of a specific length with linspace
  12. 3.12 Making linspace more like arange using the endpoint parameter
  13. 3.13 Obtaining the linspace step size
  14. 3.14 Other sequence generators
  15. 3.15 Creating an identity matrix
  16. 3.16 Creating an eye matrix
  17. 3.17 Using vectorisation

4 Vectorisation

  1. 4.1 Performing simple maths on an array
  2. 4.2 Vectorisation with other data types
  3. 4.3 Vectorisation with multi-dimensional arrays
  4. 4.4 Expressions using two arrays
  5. 4.5 Expressions using two multi-dimensional arrays
  6. 4.6 More complex expressions
  7. 4.7 Using conditional operators
  8. 4.8 Combining conditional operators

5 Universal functions

  1. 5.1 Example universal function - sqrt
  2. 5.2 Example universal function of two arguments - power
  3. 5.3 Summary of ufuncs
  4. 5.3.1 Maths operations
  5. 5.3.2 Trigonometric functions
  6. 5.3.3 Bit manipulation
  7. 5.3.4 Comparison functions
  8. 5.3.5 Logical functions
  9. 5.3.6 Min and max
  10. 5.3.7 Float functions
  11. 5.4 ufunc methods
  12. 5.4.1 Reduce
  13. 5.4.2 Accumulation
  14. 5.5 Optional keyword arguments for ufuncs
  15. 5.5.1 out
  16. 5.5.2 where

6 Indexing, slicing and broadcasting

  1. 6.1 Indexing an array
  2. 6.1.1 Indexing in 1 dimension
  3. 6.1.2 Indexing in 2 dimensions
  4. 6.1.3 Picking a row or column in 2-dimensions
  5. 6.1.4 Indexing in 3 dimensions
  6. 6.1.5 Picking a row or column in a 3D array
  7. 6.1.6 Picking a matrix in a 3D array
  8. 6.2 Slicing an array
  9. 6.2.1 Slicing lists - a recap
  10. 6.2.2 Slicing 1D NumPy arrays
  11. 6.2.3 Slicing a 2D array
  12. 6.2.4 Slicing a 3D array
  13. 6.2.5 Full slices
  14. 6.3 Slices vs indexing
  15. 6.4 Views
  16. 6.5 Broadcasting
  17. 6.5.1 Broadcasting from 1 to 2 dimensions
  18. 6.5.2 Broadcasting 1 to 3 dimensions
  19. 6.5.3 Broadcasting 2 to 3 dimensions
  20. 6.6 Broadcasting rules
  21. 6.7 Broadcasting a column vector
  22. 6.8 Broadcasting a row vector and a column vector
  23. 6.9 Broadcasting scalars
  24. 6.10 Efficient broadcasting
  25. 6.11 Fancy indexing

7 Array manipulation functions

  1. 7.1 Copying an array
  2. 7.2 Changing the type of an array
  3. 7.3 Changing the shape of an array
  4. 7.4 Splitting arrays
  5. 7.4.1 Splitting along different axes
  6. 7.4.2 Unequal splits
  7. 7.4.3 Alternative functions
  8. 7.5 Stacking arrays
  9. 7.5.1 Stacking 2-dimensional arrays

8 File input and output

  1. 8.1 CSV format
  2. 8.2 Writing CSV data
  3. 8.2.1 Adding a header or footer
  4. 8.2.2 Changing the line separator
  5. 8.2.3 Compressing the output file
  6. 8.3 Reading CSV data
  7. 8.3.1 Skipping header or footer
  8. 8.3.2 Reading compressing file

9 Using Matplotlib with NumPy

  1. 9.1 Installing Matplotlib
  2. 9.2 Plotting a histogram
  3. 9.3 Plotting functions
  4. 9.4 Plotting functions with NumPy
  5. 9.5 Creating a heatmap

10 Reference

  1. 10.1 Data types
  2. 10.1.1 Unsigned integer sizes and ranges
  3. 10.1.2 Signed integer sizes and ranges
  4. 10.1.3 Integer wrap-around
  5. 10.1.4 Float characteristics
  6. 10.1.5 Complex characteristics

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub