簡體   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