[SciPy-user] jn & lpmn or sph_jn...
fred
fredantispam at free.fr
Thu Jul 27 17:35:34 EDT 2006
Hi,
I like how jn works because I can array as arg (I use jn on 3D array).
This is not the case for sph_jn & lpmn :-(
I tried to bypass it, with something like
def foo(m,n):
x = arange(0,Lx,dx)
y = arange(0,Ly,dy)
z = arange(0,Lz,dz)
tab = zeros((len(x), len(y), len(z)), dtype='f')
for i in range(0,len(x)):
for j in range(0,len(y)):
for k in range(0,len(z)):
tab[i,j,k] = cos(theta(x[i],y[j],z[k]))
# tab[i,j,k] =
Ymn_theta_p(x[i],y[j],z[k],m,n)*sph_jn(n,r(x[i],y[j],z[k]))[n][0]*rho(x[i],y[j],z[k])
return (tab)
but knowing my arrays have more than hundred of thousand cells, it is
_very_ slow.
I guess sph_jn & lpmn are written like this because they return arrays
(0 to n order, derivative, etc).
I wish to have Legendre & spherical Bessel functions which could accept
array as arg.
I only need the last order (n) and the derivative (which could be called
by another func) for the same order.
How could I write this ?
Or is there another way to do the same thing ?
Ex. :
In [1]: from scipy.special import *
In [2]: x=arange(0,1,0.1)
In [3]: print jn(1,x)
[ 0. 0.04993753 0.09950083 0.14831882 0.19602658 0.24226846
0.28670099 0.32899574 0.36884205 0.40594955]
In [4]: print sph_jn(1,x)
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/home/fred/<ipython console>
/usr/local/lib/python2.4/site-packages/scipy/special/basic.py in
sph_jn(n, z)
212 """
213 if not (isscalar(n) and isscalar(z)):
--> 214 raise ValueError, "arguments must be scalars."
215 if (n!= floor(n)) or (n<0):
216 raise ValueError, "n must be a non-negative integer."
ValueError: arguments must be scalars.
Cheers,
--
Fred.
More information about the SciPy-User
mailing list