Skip to main content

entropy

Calculates Shannon entropy of a column of values.

Syntax

entropy(val)

Arguments

  • val β€” Column of values of any type.

Returned value

  • Shannon entropy.

Type: Float64.

Example

Query:

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;

Result:

β”Œβ”€entropy(vals)─┬─entropy(strings)─┐
β”‚ 1 β”‚ 1.75 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜