To solve a set of linear equations, find the values of its unknowns. NumPy’s np.linalg.solve() does that when the coefficient matrix has the same number of rows and columns and its equations are independent. I’ll show how to put the…
For a set of numbers, you can use a base-2 logarithm to express each value as an exponent on two. NumPy’s log2 function calculates that result element by element for array-like input. This article shows how to apply np.log2 to…
To estimate a numeric target from input values, regression gives you a way to model how those values relate to the target. NumPy’s least-squares routine finds coefficients from arrays, with each coefficient describing how an input value changes the prediction.…
To decompose a matrix in NumPy, use SVD. SVD expresses the matrix as a product of factors. I’ll explain the shapes of those factors and show how to reconstruct the matrix or make a lower-rank approximation. TL;DR: NumPy SVD returns…
When the next calculation needs an array of zeros that lines up with an array you already have, NumPy can build it for you. np.zeros_like creates that array, copying the shape and data type of the one you give it.…
When you’re about to fill a NumPy array with your own values straight away, you only need NumPy to set aside the space. np.empty creates that array without setting its values, and np.empty_like does the same using another array’s shape…
Given a point’s x and y coordinates, you may need the angle it makes with the x-axis. np.arctan2 calculates that angle and uses the signs of both coordinates to put it in the right quadrant. You’ll get the angle in…
Python lists can hold numbers, but doing math on every element means writing a loop. A NumPy array stores numbers of one type in a grid, so you can calculate on the whole array at once. Here I’ll create arrays…
To find the average of numbers stored in a NumPy array, you don’t need to add them up yourself. np.mean calculates the average of the whole array, or a separate average for each row or column. Here I’ll show both…
The final np.gradient estimate can be negative even when the sample values rise, if the coordinates step backward from 9.0 to 0.1. That negative result makes the role of coordinate order clear to me. Pair each slope with the coordinate…
You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.