> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 计算一列值的香农熵。

# entropy

<div id="entropy">
  ## entropy
</div>

引入版本：v20.1.0

计算某一列值的 [香农熵](https://en.wikipedia.org/wiki/Entropy_\(information_theory\))。

**语法**

```sql theme={null}
entropy(val)
```

**参数**

* `val` — 任意类型的值列。[`Any`](/zh/reference/data-types)

**返回值**

返回香农熵。[`Float64`](/zh/reference/data-types/float)

**示例**

**基础熵计算**

```sql title=Query theme={null}
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
```

```response title=Response theme={null}
┌─entropy(vals)─┬─entropy(strings)─┐
│             1 │             1.75 │
└───────────────┴──────────────────┘
```
