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

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...

lock icon The rest of the chapter is locked
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}