我注意到,爲了n和自變量x jv(n,x)
的scipy.special
貝塞爾函數矢量在X:python中的矢量化球形bessel函數?
In [14]: import scipy.special as sp In [16]: sp.jv(1, range(3)) # n=1, [x=0,1,2] Out[16]: array([ 0., 0.44005059, 0.57672481])
但還有的球貝塞爾函數沒有相應的量化形式,sp.sph_jn
:
In [19]: sp.sph_jn(1,range(3))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-ea59d2f45497> in <module>()
----> 1 sp.sph_jn(1,range(3)) #n=1, 3 value array
/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/scipy/special/basic.pyc in sph_jn(n, z)
262 """
263 if not (isscalar(n) and isscalar(z)):
--> 264 raise ValueError("arguments must be scalars.")
265 if (n != floor(n)) or (n < 0):
266 raise ValueError("n must be a non-negative integer.")
ValueError: arguments must be scalars.
此外,球形貝塞爾函數在一次通過中計算N的所有階數。所以如果我想爲參數x=10
使用Bessel函數,它會返回n = 1,2,3,4,5。它實際上返回JN並且每通導數:
In [21]: sp.sph_jn(5,10)
Out[21]:
(array([-0.05440211, 0.07846694, 0.07794219, -0.03949584, -0.10558929,
-0.05553451]),
array([-0.07846694, -0.0700955 , 0.05508428, 0.09374053, 0.0132988 ,
-0.07226858]))
爲什麼在API中的這種不對稱的存在,並沒有任何人知道,將返回球貝塞爾函數向量化,或者至少更迅速地庫(即在用Cython)?
這是在scipy.special已知功能要求(關於如何落實這些矢量化版本進行了一些指導):https://github.com/scipy/scipy/issues/3113。 – 2015-02-10 22:30:22
如果有人有開箱即用的實施,請發佈!感謝分享 – 2015-02-11 00:41:51