Mastering Numerical Computing with NumPy
eBook - ePub

Mastering Numerical Computing with NumPy

Master scientific computing and perform complex operations with ease

  1. 248 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Numerical Computing with NumPy

Master scientific computing and perform complex operations with ease

About this book

Enhance the power of NumPy and start boosting your scientific computing capabilitiesAbout This Book• 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 toolWho This Book Is ForMastering 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 systemIn DetailNumPy 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.Style and approachThis mastering guide will help you master your skills required to perform a complex numerical computation. The book contains the right mixture of theory and practical examples that will help you in dealing with the advanced NumPy and build solutions for your numeric and scientific computational problems

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

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 be turned into linear equations where you can analyze the interaction of features in a given space. Imagine a case where you are working on an image recognition project and your task is to detect a tumor in the brain from MRI images. Technically, your algorithm should act like a doctor, where it scans the given input and detects the tumor in the brain. A doctor has the advantage of being able to spot anomalies; the human brain has been evolving through thousands of years to interpret visual input. Without much effort, a human can capture anomalies intuitively. However, for an algorithm to perform a similar task, you should think about this process in as much detail as possible to understand how you can formally express it so that the machines can understand.
First, you should think about how MRI data is stored in a computer, which processes only 0s and 1s. The computer actually stores pixel intensities in structures, called matrices. In other words, you will convert an MRI as a vector of dimensions, N2, where each element consists of pixel values. If this MRI has a 512 x 512 dimension, each pixel will be one point in 262,144 in pixels. Therefore, any computational manipulation that you will do in this Matrix would most likely use Linear Algebra principles. If this example is not enough to demonstrate the importance of Linear Algebra in ML, then let's look at a popular example in deep learning. In a nutshell, deep learning is an algorithm that uses neural network structure to learn the desired output (label) by continuously updating the weights of neuron connections between layers. A graphical representation of a simple deep learning algorithm is as follows:
Neural networks store weights between layers and bias values in matrices. As these are the parameters that you try to tune in to your deep learning model in order to minimize your loss function, you continuously make computations and update them. In general, ML models require heavy calculations and need to be trained for big datasets to provide efficient results. This is why linear algebra is a fundamental part of ML.
In this chapter, we will use numpy library but note that most linear algebra functions are also imported by scipy and they are more properly belong to it. Ideally, in most cases, you import both of these libraries and perform computations. One important feature of scipy is to have fully-featured versions of the linear algebra modules. We highly encourage you to review scipy documentation and practice using same operations with scipy throughout this chapter. Here's the link for linear algebra module of scipy: https://docs.scipy.org/doc/scipy/reference/linalg.html.
In this chapter, we will cover the following topics:
  • Vector and matrix mathematics
  • What's an eigenvalue and how do we compute it?
  • Computing the norm and determinant
  • Solving linear equations
  • Computing gradient

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, 35],
[25, 34, 43, 52, 61]])
In [4]: a@b
Out[4]: array([[ 5, 6...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Packt Upsell
  4. Contributors
  5. Preface
  6. Working with NumPy Arrays
  7. Linear Algebra with NumPy
  8. Exploratory Data Analysis of Boston Housing Data with NumPy Statistics
  9. Predicting Housing Prices Using Linear Regression
  10. Clustering Clients of a Wholesale Distributor Using NumPy
  11. NumPy, SciPy, Pandas, and Scikit-Learn
  12. Advanced Numpy
  13. Overview of High-Performance Numerical Computing Libraries
  14. Performance Benchmarks
  15. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Mastering Numerical Computing with NumPy by Umit Mert Cakmak, Mert Cuhadaroglu in PDF and/or ePUB format, as well as other popular books in Computer Science & Data Mining. We have over one million books available in our catalogue for you to explore.