NumPy Recipes
()
About this ebook
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.
Read more from Martin Mc Bride
Computer Graphics in Python Rating: 0 out of 5 stars0 ratingsImage Processing in Python Rating: 0 out of 5 stars0 ratings
Related to NumPy Recipes
Related ebooks
Practical Python Data Visualization: A Fast Track Approach To Learning Data Visualization With Python Rating: 4 out of 5 stars4/5Mastering Python Scientific Computing Rating: 4 out of 5 stars4/5Numpy Simply In Depth Rating: 5 out of 5 stars5/5Learning NumPy Array Rating: 0 out of 5 stars0 ratingsMatplotlib for Python Developers Rating: 3 out of 5 stars3/5Exploring the Python Library Ecosystem: A Comprehensive Guide Rating: 0 out of 5 stars0 ratingsLearning PyTorch 2.0, Second Edition: Utilize PyTorch 2.3 and CUDA 12 to experiment neural networks and deep learning models Rating: 0 out of 5 stars0 ratingsNumerical Python: Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib Rating: 0 out of 5 stars0 ratingsAdvanced Python Development: Using Powerful Language Features in Real-World Applications Rating: 0 out of 5 stars0 ratingsClojure Programming Cookbook Rating: 0 out of 5 stars0 ratingsMachine Learning Systems: Designs that scale Rating: 0 out of 5 stars0 ratingsFunctional Python Programming Rating: 0 out of 5 stars0 ratingsMastering matplotlib Rating: 0 out of 5 stars0 ratingsLarge Scale Machine Learning with Python Rating: 2 out of 5 stars2/5Python: Programming For Intermediates: Learn The Basics Of Python In 7 Days! Rating: 0 out of 5 stars0 ratingsScientific Computing with Python 3 Rating: 0 out of 5 stars0 ratingsModular Programming with Python Rating: 0 out of 5 stars0 ratingsFunctional Python Programming, 3rd edition: Use a functional approach to write succinct, expressive, and efficient Python code Rating: 0 out of 5 stars0 ratingsIntroduction to Python 2018 Edition Rating: 4 out of 5 stars4/5Mastering Python: A Comprehensive Guide to Programming Rating: 0 out of 5 stars0 ratingsPython from the Very Beginning Rating: 0 out of 5 stars0 ratingsMastering SciPy Rating: 0 out of 5 stars0 ratingsMastering PyCharm Rating: 5 out of 5 stars5/5TensorFlow A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsLearning IPython for Interactive Computing and Data Visualization - Second Edition Rating: 2 out of 5 stars2/5NumPy Cookbook Rating: 5 out of 5 stars5/5Julia for Data Analysis Rating: 0 out of 5 stars0 ratingsInteractive Applications Using Matplotlib Rating: 0 out of 5 stars0 ratingsLearning SciPy for Numerical and Scientific Computing - Second Edition Rating: 0 out of 5 stars0 ratingsF# for Machine Learning Essentials Rating: 0 out of 5 stars0 ratings
Programming For You
Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5JavaScript All-in-One For Dummies Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Raspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5C Programming For Beginners: The Simple Guide to Learning C Programming Language Fast! Rating: 5 out of 5 stars5/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Learn JavaScript in 24 Hours Rating: 3 out of 5 stars3/5Microsoft Azure For Dummies Rating: 0 out of 5 stars0 ratingsSpies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Nostalgia and Videogame Music: A Primer of Case Studies, Theories, and Analyses for the Player-Academic Rating: 0 out of 5 stars0 ratingsCoding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for NumPy Recipes
0 ratings0 reviews
Book preview
NumPy Recipes - Martin McBride
NumPy Recipes
A practical introduction to NumPy
Martin McBride
© 2020 Martin McBride
Table of Contents
Foreword
Who is this book for?
About the author
Keep in touch
1 Introduction to NumPy
1.1 Installing NumPy
1.2 What is NumPy?
1.3 NumPy vs Python lists
1.4 Advantages of NumPy
1.5 NumPy universal functions
1.6 Compatibility with other libraries
2 Anatomy of a NumPy array
2.1 NumPy arrays compared to lists
2.2 Printing the characteristics of an array
2.2.1 Rank
2.2.2 Shape
2.2.3 Size
2.2.4 Data type
2.2.5 Item size
2.2.6 Data location
2.3 Array rank examples
2.4 Data types
2.4.1 Integers
2.4.2 Unsigned integers
2.4.3 Floating point values
2.4.4 Complex number formats
2.4.5 Boolean
2.4.6 List of main data types
3 Creating arrays
3.1 Creating an array of zeroes
3.2 Creating other fixed content arrays
3.3 Choosing the data type
3.4 Creating multi-dimensional arrays
3.5 Creating like arrays
3.6 Creating an array from a Python list
3.7 Controlling the type with the array function
3.8 array function anti-patterns
3.9 Creating a value series with arange
3.10 Rounding error problem with arange
3.11 Create a sequence of a specific length with linspace
3.12 Making linspace more like arange using the endpoint parameter
3.13 Obtaining the linspace step size
3.14 Other sequence generators
3.15 Creating an identity matrix
3.16 Creating an eye matrix
3.17 Using vectorisation
4 Vectorisation
4.1 Performing simple maths on an array
4.2 Vectorisation with other data types
4.3 Vectorisation with multi-dimensional arrays
4.4 Expressions using two arrays
4.5 Expressions using two multi-dimensional arrays
4.6 More complex expressions
4.7 Using conditional operators
4.8 Combining conditional operators
5 Universal functions
5.1 Example universal function - sqrt
5.2 Example universal function of two arguments - power
5.3 Summary of ufuncs
5.3.1 Maths operations
5.3.2 Trigonometric functions
5.3.3 Bit manipulation
5.3.4 Comparison functions
5.3.5 Logical functions
5.3.6 Min and max
5.3.7 Float functions
5.4 ufunc methods
5.4.1 Reduce
5.4.2 Accumulation
5.5 Optional keyword arguments for ufuncs
5.5.1 out
5.5.2 where
6 Indexing, slicing and broadcasting
6.1 Indexing an array
6.1.1 Indexing in 1 dimension
6.1.2 Indexing in 2 dimensions
6.1.3 Picking a row or column in 2-dimensions
6.1.4 Indexing in 3 dimensions
6.1.5 Picking a row or column in a 3D array
6.1.6 Picking a matrix in a 3D array
6.2 Slicing an array
6.2.1 Slicing lists - a recap
6.2.2 Slicing 1D NumPy arrays
6.2.3 Slicing a 2D array
6.2.4 Slicing a 3D array
6.2.5 Full slices
6.3 Slices vs indexing
6.4 Views
6.5 Broadcasting
6.5.1 Broadcasting from 1 to 2 dimensions
6.5.2 Broadcasting 1 to 3 dimensions
6.5.3 Broadcasting 2 to 3 dimensions
6.6 Broadcasting rules
6.7 Broadcasting a column vector
6.8 Broadcasting a row vector and a column vector
6.9 Broadcasting scalars
6.10 Efficient broadcasting
6.11 Fancy indexing
7 Array manipulation functions
7.1 Copying an array
7.2 Changing the type of an array
7.3 Changing the shape of an array
7.4 Splitting arrays
7.4.1 Splitting along different axes
7.4.2 Unequal splits
7.4.3 Alternative functions
7.5 Stacking arrays
7.5.1 Stacking 2-dimensional arrays
8 File input and output
8.1 CSV format
8.2 Writing CSV data
8.2.1 Adding a header or footer
8.2.2 Changing the line separator
8.2.3 Compressing the output file
8.3 Reading CSV data
8.3.1 Skipping header or footer
8.3.2 Reading compressing file
9 Using Matplotlib with NumPy
9.1 Installing Matplotlib
9.2 Plotting a histogram
9.3 Plotting functions
9.4 Plotting functions with NumPy
9.5 Creating a heatmap
10 Reference
10.1 Data types
10.1.1 Unsigned integer sizes and ranges
10.1.2 Signed integer sizes and ranges
10.1.3 Integer wrap-around
10.1.4 Float characteristics
10.1.5 Complex characteristics
Foreword
This book aims to provide an introduction to the use and application of the Python NumPy library. NumPy is a large library, and this book introduces many of its most important features in the form of recipes for performing certain functions. This provides a practical grounding that can be used as a basis for understanding the extensive documentation available from the NumPy website.
Who is this book for?
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.
About the author
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 available on leanpub.com. He is interested in generative art and works on the generativepy open source project.
Keep in touch
If you have any comments or questions you can get in touch by any of the following methods:
Joining the Python Informer forum at http://pythoninformer.boards.net/. Follow the NumPy board in the Books section.
Signing up for the Python Informer newsletter at pythoninformer.com
Following @pythoninformer on twitter.
Contacting me directly by email (info@axlesoft.com).
1 Introduction to NumPy
This is a brief overview of what NumPy is, and why makes it so useful. But first, we will