polars entropy

For dataframe.

Compute the entropy as `-sum(pk * log(pk))` where `pk` are discrete probabilities.

warning This command requires a plugin The polars entropy command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.

Command Type

plugin

Signature

> polars entropy {flags}

Flags

  • --base {float}: Given base, defaults to e.
  • --normalize {bool}: Normalize pk if it doesn’t sum to 1. Default to true.

Input/output types:

input output
polars_expression polars_expression
polars_selector polars_expression

Examples

Compute the entropy of a column expression

> [[a]; [1] [2] [3]] | polars into-df | polars select (polars col a | polars entropy --base 2) | polars collect
╭───┬──────╮
│ # │  a   │
├───┼──────┤
│ 0 │ 1.46 │
╰───┴──────╯

Compute the entropy of a column expression without normalization

> [[a]; [1] [2] [3]] | polars into-df | polars select (polars col a | polars entropy --base 2 --normalize false) | polars collect
╭───┬───────╮
│ # │   a   │
├───┼───────┤
│ 0 │ -6.75 │
╰───┴───────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.