Home / Maths for AI / Symbols / Functions

Logarithm

Say it: "log of x", "ln x" for the natural log

What it means

log⁡bx\log_b x is the power you raise bb to, to get xx: log⁡101000=3\log_{10} 1000 = 3. ln⁡x\ln x (or just log⁡x\log x in ML) uses base ee. Logs turn products into sums: log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b.

Example

log⁡28=3because23=8\log_2 8 = 3 \quad\text{because}\quad 2^3 = 8

The log undoes the power.

In code

import numpy as np
print(np.log2(8), np.log10(1000), np.log(np.e))

Output

3.0 3.0 1.0

Where it appears in machine learning

Log-likelihood, cross-entropy loss, log-probabilities from language models, and log scales for skewed data.

Related symbols

Learn it properly in the free lesson Reading ML Maths, with practice questions that check your answers.