Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Numerical Computing with NumPy

You're reading from  Mastering Numerical Computing with NumPy

Product type Book
Published in Jun 2018
Publisher Packt
ISBN-13 9781788993357
Pages 248 pages
Edition 1st Edition
Languages
Authors (3):
Umit Mert Cakmak Umit Mert Cakmak
Profile icon Umit Mert Cakmak
Tiago Antao Tiago Antao
Profile icon Tiago Antao
Mert Cuhadaroglu Mert Cuhadaroglu
Profile icon Mert Cuhadaroglu
View More author details

Table of Contents (11) Chapters

Preface Working with NumPy Arrays Linear Algebra with NumPy Exploratory Data Analysis of Boston Housing Data with NumPy Statistics Predicting Housing Prices Using Linear Regression Clustering Clients of a Wholesale Distributor Using NumPy NumPy, SciPy, Pandas, and Scikit-Learn Advanced Numpy Overview of High-Performance Numerical Computing Libraries Performance Benchmarks Other Books You May Enjoy

Advanced Numpy

Many libraries have nice and easy to use APIs. All you need to do is to invoke the provided API function and library will handle the rest of it for you. What's happening under the hood is not your concern and you are only interested in output. This is fine for most cases, however it's important to understand at least the basic internal of a library you are using. Understanding internals will help you to grasp what's going on with your code and what are the red flags that you should avoid while developing your applications.

In this chapter, NumPy internals will be reviewed such as NumPy's type hierarchy and memory usage. At the end of this chapter, you will learn about the code profiling to inspect your programs line by line.

NumPy internals

As you have seen in previous chapters, NumPy arrays make numerical computations efficient and its API is intuitive and easy to use. NumPy array are also core to other scientific libraries as many of them are built on top of NumPy arrays.

In order to write better and more efficient code, you need to understand the internals of data handling. A NumPy array and its metadata live in a data buffer, which is a dedicated block of memory with certain data items.

How does NumPy manage memory?

Once you initialize a NumPy array, its metadata and data are stored at allocated memory locations in Random Access Memory (RAM).

import numpy as np
array_x = np.array([100.12, 120.23, 130.91])

First, Python is a dynamically typed...

Summary

Knowing NumPy's internals is crucially important when you are working with scientific operations. Efficiency is key since many scientific computations are compute and memory intensive. Hence, if your code is not written efficiently, computations will take much longer than they need and this will hurt your research and development timeline.

In this chapter, you have seen some of the internals and performance aspects of the NumPy library and also learned about the vprof library, which helps you inspect the performance of your python programs.

Code profiling will help you a lot to inspect your programs line by line and there are different ways of looking at the same data, as you have seen previously. Once you have identified the most demanding parts of your programs, then you can start searching for more efficient ways or implementations to improve performance and save...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Mastering Numerical Computing with NumPy
Published in: Jun 2018 Publisher: Packt ISBN-13: 9781788993357
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}