繁体   English   中英

使用 scipy.integrate 使用广播的方法?

[英]A way to use broadcasting using scipy.integrate?

我正在尝试对 x 执行 function f(x, t) 的积分,并针对 t 绘制结果 F(t) 的 plot。

import scipy.integrate as integrate
import scipy.special as special
import numpy as np
import matplotlib.pyplot as plt

resNumb = [integrate.quad(lambda x: 0.5*(x-1)*( special.laguerre(35)(x*np.exp(-tau)) )**2*np.exp(-x), 0, np.inf)[0] for tau in list(np.linspace(0,1,50))]


r = np.sqrt(1-np.exp(-np.linspace(0,1,50)))


plt.scatter(r,resNumb)

I wish to make this process faster by making python to integrate this function having numpy array of tau as an argument, but scipy.integrate does not seem to support such input. 我查找了 numpy.vectorize,但它并没有提高程序的速度。 有没有办法提高这个过程的速度?

像下面这样使用integrate.quad_vec()

tau = np.linspace(0, 1, 50)
resNumb, _ = integrate.quad_vec(
    lambda x: 0.5*(x-1) * ( special.laguerre(35)(x*np.exp(-tau)) )**2 * np.exp(-x),
    0, np.inf)

但是该算法牺牲了性能的准确性,如参考文献中所述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM