Math
Understand how arithmetic and linear algebra work in NumPy.
We'll cover the following...
Chapter Goals:
- Learn how to perform math operations in NumPy
- Write code using NumPy math functions
A. Arithmetic
One of the main purposes of NumPy is to perform multi-dimensional arithmetic. Using NumPy arrays, we can apply arithmetic to each element with a single operation.
The code below shows multi-dimensional arithmetic with NumPy.
Using NumPy arithmetic, we can easily modify large amounts of numeric data with only a few operations. For example, we could convert a dataset of Fahrenheit temperatures to their equivalent Celsius form.
The code below converts Fahrenheit to Celsius in NumPy.
It is important to note that performing arithmetic on NumPy arrays does not change the original array, and instead produces a new array that is the result of the arithmetic operation.
B. Non-linear functions
Apart from basic arithmetic operations, NumPy also allows you to use non-linear functions such as exponentials and logarithms.
The function ...