No project description provided
Project description
pycw_fn
- efficient piecewise functions in Python
This package is a Python wrapper around the pcw_fn
Rust crate built using maturin. It supports arbitrary piecewise functions on the real line.
Example
This example constructs a few piecewise functions, does some basic arithmetic with them and finally plots them:
import numpy as np
import matplotlib.pyplot as plt
from numpy.polynomial import Polynomial
from pycw_fn import PcwFn
g_0 = PcwFn.from_funcs_and_jumps(
[
Polynomial([1, 5, -10], window=np.array([-1., 1.]),
domain=np.array([-1., 1.])),
Polynomial([0, 10, -20, 10], window=np.array([-1., 1.]),
domain=np.array([-1., 1.])),
],
[
0.5,
],
)
g_1 = PcwFn.from_funcs_and_jumps(
[
Polynomial([0.4*a**2, -4*a, 10], window=np.array([-1., 1.]),
domain=np.array([-1., 1.])) for a in range(6)
],
[
0.1,
0.3,
0.5,
0.7,
0.9,
],
)
b_2 = Polynomial([1/10, -4, 40])
g_2 = PcwFn.from_funcs_and_jumps(
[b_2(Polynomial([-0.1*a, 1])) for a in range(10)],
np.linspace(0.1, 1, num=9, endpoint=False),
)
g = g_0 + 5 * g_2
ts = np.linspace(0, 1, num=1000)
ys = g(ts)
plt.plot(ts, ys)
plt.show()
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
pycw_fn-0.1.1.tar.gz
(6.7 kB
view hashes)
Built Distribution
Close
Hashes for pycw_fn-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d9f424e461901a189ab56f214888b0a241bb7625bcc9896fc1af7cc614e85f |
|
MD5 | 3b491526159a190500ea2478ca4104fe |
|
BLAKE2b-256 | 69decc3c7f4811126ab8fc39ed5616017f1d5036abd4c7caa8cde20812d4b630 |