Category Python Modules

Modules is one of the best feature of Python. Except some core modules, you can install what you need and keep your Python setup smooth.

Python sys Module: Arguments, Paths, and Streams

Python sys Module: Arguments, Paths, and Streams

Command-line arguments let a Python script receive values supplied when it starts. The sys module exposes those argument strings alongside information maintained by the running interpreter. I’ll show how to read sys.argv and check whether an optional argument is present…

np.outer(): Outer Product in NumPy

np.outer(): Outer Product in NumPy

To calculate every pairwise product between two inputs, use NumPy’s np.outer function. It multiplies each value in one input by each value in the other and returns a two-dimensional array. This article explains how the input shapes determine the result…

np.linalg.solve() Linear Systems

np.linalg.solve() Linear Systems

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…

Statsmodels Library Structure and Imports

Statsmodels Library Structure and Imports

Finding an import in Statsmodels starts with the model or helper you want to use. The package groups models, tests and tools into subpackages by subject, while an API module collects selected objects for convenient use. I’ll show how to…

Python Logarithm Base 2 Using NumPy log2()

Python Logarithm Base 2 Using NumPy log2()

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…

Pandas Get Dummies: Encode Categories

Pandas Get Dummies: Encode Categories

Turning category labels into indicator columns gives a pandas table one column for each category. pandas.get_dummies() creates those columns, using Boolean values by default or integers when you set dtype=int. I’ll show how to encode selected columns and align training…

Regression in Python: Fit Models with NumPy

Regression in Python: Fit Models with NumPy

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

SVD NumPy: Decompose a Matrix

SVD NumPy: Decompose a Matrix

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…