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.0.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for pycw_fn-0.1.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6f009386a5fea226fbe6c90f705bda1733ecbc372a436d7f1f80f7772bd68b1 |
|
MD5 | 51ee3f7ac98c3b7654e05987e69324ed |
|
BLAKE2b-256 | dee31a4f62810fd88012bc5bb134d823f5cca702e2d831688c1fe53080024439 |