Random number generation as polars expressions
Project description
polars_rng
Random number generation in Polars.
Usage
All random number generators are implmented as Polars expressions and can be used anywhere that expressions are allowed, including in lazy contexts.
import polars as pl
import polars_rng as prng
# simulate data from a linear model
# y = x^2 + N(0, 3^2)
(
pl.DataFrame(dict(x = [-3, 0, 2, 3, 4, 6, 11]))
.with_columns(
y = prng.normal(mu = pl.col("x").pow(2), sigma = 3)
)
)
# shape: (7, 2)
# ┌─────┬────────────┐
# │ x ┆ y │
# │ --- ┆ --- │
# │ i64 ┆ f64 │
# ╞═════╪════════════╡
# │ -3 ┆ 8.623695 │
# │ 0 ┆ -7.884036 │
# │ 2 ┆ 2.864818 │
# │ 3 ┆ 5.348727 │
# │ 4 ┆ 19.721068 │
# │ 6 ┆ 37.855376 │
# │ 11 ┆ 123.532992 │
# └─────┴────────────┘
# lazily simulate from binomial
lazy = (
pl.LazyFrame()
.select(n_coins = pl.repeat(10, 6))
.with_columns(
n_heads = prng.binomial(p = .5, n = "n_coins")
)
)
lazy
# <LazyFrame at 0x1150E94F0>
lazy.collect()
# shape: (6, 2)
# ┌─────────┬─────────┐
# │ n_coins ┆ n_heads │
# │ --- ┆ --- │
# │ i32 ┆ f64 │
# ╞═════════╪═════════╡
# │ 10 ┆ 4.0 │
# │ 10 ┆ 7.0 │
# │ 10 ┆ 6.0 │
# │ 10 ┆ 3.0 │
# │ 10 ┆ 2.0 │
# │ 10 ┆ 5.0 │
# └─────────┴─────────┘
Available Distributions
A full list of implmented distributions is available in the main namespace:
from polars_rng import DISTRIBUTIONS
DISTRIBUTIONS
# ['normal',
# 'uniform',
# 'bernoulli',
# 'binomial',
# 'exponential',
# 'poisson',
# 'weibull',
# 'laplace',
# 'gamma',
# 'beta']
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_rng-0.1.0.tar.gz.
File metadata
- Download URL: polars_rng-0.1.0.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9092b5685692794d4aa7a4e16c96d11d19b194bed5a22593a8c2e37363c343fe
|
|
| MD5 |
0daacd87201f53fe07934aca6bea67ec
|
|
| BLAKE2b-256 |
468ffd7120d7fd84723dc5433c3ca1e9555c1f60c35439729fe15faee9af8682
|
File details
Details for the file polars_rng-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: polars_rng-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dda309af180fa49d93b6f5e59fd0f04e05cdbf5f2dd659fde8049214f5b6adc
|
|
| MD5 |
ba4a72b92524f996568a9da49aecb9d3
|
|
| BLAKE2b-256 |
dbc94d992296b04ba2c82664a6ab1a6c5fb6d342ce64dbcad1d9845976363b89
|