Skip to main content
Skip to main content

entropy

entropy

Introduced in: v20.1

Calculates the Shannon entropy for a column of values.

Syntax

entropy(val)

Arguments

  • val — Column of values of any type. Any

Returned value

Returns Shannon entropy. Float64

Examples

Basic entropy calculation

CREATE TABLE entropy (`vals` UInt32,`strings` String)
ENGINE = Memory;

INSERT INTO entropy VALUES (1, 'A'), (1, 'A'), (1,'A'), (1,'A'), (2,'B'), (2,'B'), (2,'C'), (2,'D');

SELECT entropy(vals), entropy(strings) FROM entropy
┌─entropy(vals)─┬─entropy(strings)─┐
│             1 │             1.75 │
└───────────────┴──────────────────┘