mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 03:52:15 +00:00
af86aea90d
* initial commit * Update draft * small fix
44 lines
850 B
Markdown
44 lines
850 B
Markdown
---
|
|
toc_priority: 302
|
|
---
|
|
|
|
# entropy {#entropy}
|
|
|
|
Calculates [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of a column of values.
|
|
|
|
**Syntax**
|
|
|
|
``` sql
|
|
entropy(val)
|
|
```
|
|
|
|
**Arguments**
|
|
|
|
- `val` — Column of values of any type.
|
|
|
|
**Returned value**
|
|
|
|
- Shannon entropy.
|
|
|
|
Type: [Float64](../../../sql-reference/data-types/float.md).
|
|
|
|
**Example**
|
|
|
|
Query:
|
|
|
|
``` sql
|
|
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:
|
|
|
|
``` text
|
|
┌─entropy(vals)─┬─entropy(strings)─┐
|
|
│ 1 │ 1.75 │
|
|
└───────────────┴──────────────────┘
|
|
```
|