cython中的和平插值与惰性评价
bpf4的Python项目详细描述
关于
bpf4是python中用于曲线拟合和断点函数的库。它主要是用cython编程以提高效率。它本身已经被用于函数和数值分析。
示例
找到两条曲线之间的交点
>>> from bpf4 import bpf # this imports the api >>> import pylab >>> a = bpf.spline((0, 0), (1, 5), (2, 3), (5, 10)) # each point (x, y) >>> b = bpf.expon((0, -10), (2,15), (5, 3), exp=3) >>> a.plot() # uses matplotlib >>> b.plot() >>> zeros = (a - b).zeros() >>> pylab.plot(zeros, a.map(zeros), 'o')
啊![1](https://github.com/gesellkammer/bpf4/raw/master/pics/zeros.png)
功能
除线性外,还有许多插值类型:
- 样条线
- 半余弦
- 指数型
- 斐波那契
- 指数半余弦
- pchip
- 对数
- 等
可以混合插值类型,以便每个段具有不同的插值(样条插值除外) 曲线可以无破坏性地组合。从上面的例子开始。
>>> c = (a + b).sin().abs() >>> c[1.5:4].plot() # plot only the range (1.5, 4)
啊![2](https://github.com/gesellkammer/bpf4/raw/master/pics/sinabs.png)
对转移、缩放和切片bpf的语法支持
>>> a >> 2 # a shifted to the right >>> (a * 5) ^ 2 # scale the x coord by 2, scale the y coord by 5 >>> a[2:2.5] # slice only a portion of the bpf >>> a[::0.01] # sample the bpf with an interval of 0.01
求导与积分:c.derivative().plot()或c.integrated().integrated().plot() 数值积分:c.积分(2,4)
依赖关系
- cython=0.19
- 努比
安装
安装最新版本(推荐)
$> git clone https://github.com/gesellkammer/bpf4.git $> cd bpf4 $> python setup.py install
否则,通过PIP或Easy_安装
$> pip install bpf4