Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Numerical Computing with NumPy
Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy: Master scientific computing and perform complex operations with ease

Arrow left icon
Profile Icon Mert Cakmak Profile Icon Tiago Antao Profile Icon Cuhadaroglu
Arrow right icon
€8.99 €23.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jun 2018 248 pages 1st Edition
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Mert Cakmak Profile Icon Tiago Antao Profile Icon Cuhadaroglu
Arrow right icon
€8.99 €23.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jun 2018 248 pages 1st Edition
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Mastering Numerical Computing with NumPy

Linear Algebra with NumPy

One of the major divisions of mathematics is algebra, and linear algebra in particular, focuses on linear equations and mapping linear spaces, namely vector spaces. When we create a linear map between vector spaces, we are actually creating a data structure called a matrix. The main usage of linear algebra is to solve simultaneous linear equations, but it can also be used for approximations for non-linear systems. Imagine a complex model or system that you are trying to understand, think of it as a non-linear model. In such cases, you can reduce the complex, non-linear characteristics of the problem into simultaneous linear equations, and you can solve them with the help of linear algebra.

In computer science, linear algebra is heavily used in machine learning (ML) applications. In ML applications, you deal with high-dimensional arrays, which can easily...

Vector and matrix mathematics

In the previous chapter, you practiced introductory operations with vectors and matrices. In this section, you will practice more advanced vector and matrix operations that are heavily used in linear algebra. Let's remember the dot product perspective on matrix manipulation and how it can be done with different methods when you have 2-D arrays. The following code block shows alternative ways of performing dot product calculation:

In [1]: import numpy as np 
a = np.arange(12).reshape(3,2)
b = np.arange(15).reshape(2,5)
print(a)
print(b)
Out[1]:
[[ 0 1]
[ 2 3]
[ 4 5]]
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
In [2]: np.dot(a,b)
Out[2]: array([[ 5, 6, 7, 8, 9],
[15, 20, 25, 30, 35],
[25, 34, 43, 52, 61]])
In [3]: np.matmul(a,b)
Out[3]: array([[ 5, 6, 7, 8, 9],
[15, 20, 25, 30...

What's an eigenvalue and how do we compute it?

An eigenvalue is a coefficient of an eigenvector. By definition, an eigenvector is a non zero vector that only changes by a scalar factor when linear transformation is applied. In general, when linear transformation is applied to a vector, its span (the line passing through its origin) is shifted, but some special vectors are not affected by these linear transformations and remain on their own span. These are what we call eigenvectors. The linear transformation affects them only by stretching or squishing them as you are multiplying this vector with a scalar. The value of this scalar is called the eigenvalue. Let's say we have a matrix A, which will be used in linear transformation. We can represent the eigenvalue and eigenvector in a mathematical statements as follows:

Here, is the eigenvector and denotes the eigenvalue...

Computing the norm and determinant

This subsection will introduce two important values in linear algebra, namely the norm and determinant. Briefly, the norm gives length of a vector. The most commonly used norm is the L2-norm, which is also known as the Euclidean norm. Formally, the Lp-norm of x is calculated as follows:

The L0-norm is actually the cardinality of a vector. You can calculate it by just counting the total number of non-zero elements. For example, the vector A =[2,5,9,0] contains three non-zero elements, therefore ||A||0 = 3. The following code block shows the same norm calculation with numpy:

In [24]: import numpy as np 
x = np.array([2,5,9,0])
np.linalg.norm(x,ord=0)
Out[24]: 3.0

In NumPy, you can calculate the norm of the vector with the use of the linalg.norm() method. The first parameter is the input array and the ord parameter is for order...

Solving linear equations

In this section, you will learn how to solve linear equations by using the linalg.solve() method. When you have a linear equation to solve, as in the form , in simple cases you can just calculate the inverse of A and then multiply it by B to get the solution, but when A has a high dimensionality, that makes it very hard computationally to calculate the inverse of A. Let's start with an example of three linear equations with three unknowns, as follows:

So, these equations can be formalized as follows with matrices:

Then, our problem is to solve . We can calculate the solution with a plain vanilla NumPy without using linalg.solve(). After inverting the A matrix, you will multiply with B in order to get results for x. In the following code block, we calculate the dot product for the inverse matrix of A and B in order to calculate :

In [44]: A =...

Computing gradient

When you have a linear line, you take the derivative so the derivative shows the slope of this line. Gradient is a generalization of the derivative when you have a multiple variable in your function, therefore the result of gradient is actually a vector function rather than a scalar value in derivative. The main goal of ML is actually finding the best model that fits your data. You can evaluate the meaning of the best as minimizing your loss function or objective function. Gradient is used for finding the value of the coefficients or a function that will minimize your loss or cost function. A well-known way of finding optimum points is taking the derivative of the objective function then setting it to zero to find your model coefficients. If you have more than one coefficient then it becomes a gradient rather than a derivative, and it becomes a vector equation...

Summary

In this chapter, we covered vector and matrix operations for linear algebra. We looked at advanced matrix operations, especially featuring dot operations. You also learned about eigenvalues and eigenvectors and then practiced their use in principal component analysis (PCA). Moreover, we covered the norm and determinant calculation and mentioned their importance and usage in ML. In the last two subsections, you learned how to convert linear equations into matrices and solve them, and looked at the computation and importance of gradients.

In the next chapter, we will use NumPy statistics to do explanatory data analysis to explore the 2015 United States Housing data.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Grasp all aspects of numerical computing and understand NumPy
  • • Explore examples to learn exploratory data analysis (EDA), regression, and clustering
  • • Access NumPy libraries and use performance benchmarking to select the right tool

Description

NumPy is one of the most important scientific computing libraries available for Python. Mastering Numerical Computing with NumPy teaches you how to achieve expert level competency to perform complex operations, with in-depth coverage of advanced concepts. Beginning with NumPy's arrays and functions, you will familiarize yourself with linear algebra concepts to perform vector and matrix math operations. You will thoroughly understand and practice data processing, exploratory data analysis (EDA), and predictive modeling. You will then move on to working on practical examples which will teach you how to use NumPy statistics in order to explore US housing data and develop a predictive model using simple and multiple linear regression techniques. Once you have got to grips with the basics, you will explore unsupervised learning and clustering algorithms, followed by understanding how to write better NumPy code while keeping advanced considerations in mind. The book also demonstrates the use of different high-performance numerical computing libraries and their relationship with NumPy. You will study how to benchmark the performance of different configurations and choose the best for your system. By the end of this book, you will have become an expert in handling and performing complex data manipulations.

Who is this book for?

Mastering Numerical Computing with NumPy is for you if you are a Python programmer, data analyst, data engineer, or a data science enthusiast, who wants to master the intricacies of NumPy and build solutions for your numeric and scientific computational problems. You are expected to have familiarity with mathematics to get the most out of this book.

What you will learn

  • • Perform vector and matrix operations using NumPy
  • • Perform exploratory data analysis (EDA) on US housing data
  • • Develop a predictive model using simple and multiple linear regression
  • • Understand unsupervised learning and clustering algorithms with practical use cases
  • • Write better NumPy code and implement the algorithms from scratch
  • • Perform benchmark tests to choose the best configuration for your system

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 28, 2018
Length: 248 pages
Edition : 1st
Language : English
ISBN-13 : 9781788996846
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 28, 2018
Length: 248 pages
Edition : 1st
Language : English
ISBN-13 : 9781788996846
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 84.97
SciPy Recipes
€29.99
Hands-On Data Analysis with NumPy and pandas
€24.99
Mastering Numerical Computing with NumPy
€29.99
Total 84.97 Stars icon
Banner background image

Table of Contents

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

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Andrey Jun 27, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good
Subscriber review Packt
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.