[SciPy-User] Vectorized spherical Bessel functions

Ondřej Čertík ondrej.certik at gmail.com
Mon Dec 2 19:17:01 EST 2013


Hi,

I need to apply spherical bessel function (values) to a vector. The
current functions accept a scalar and return two arrays of values and
derivatives as follows:

>>> from scipy.special import sph_jn
>>> sph_jn(0, 5.)
(array([-0.19178485]), array([ 0.09508941]))


So in order to vectorize it, I use:

def j0(x):
    res = empty(len(x), dtype="double")
    for i in range(len(x)):
        res[i] = sph_jn(0, x[i])[0][0]
    return res

Which is really slow for larger vectors... Any ideas how to quickly
get an array of values?

I can use Cython, etc. but I was wondering whether there is some
obvious way to do this from Python using current SciPy.

Ondrej



More information about the SciPy-User mailing list