【发布时间】:2015-01-12 16:05:06
【问题描述】:
在 2.7 中学习 Python。有没有办法避免显式循环?答案=[5, 4, 4, 3, 3, 2]
import numpy as np
import scipy.special as spe
nmax = 5 # n = 0, 1 ...5
mmax = 7 # m = 1, 2 ...7
big = 15.
z = np.zeros((nmax+1, mmax))
for i in range(nmax+1):
z[i] = spe.jn_zeros(i, mmax)
answer = [np.max(np.where(z[i]<big))+1 for i in range(nmax+1)]
print answer # list of the largest m for each n where the mth zero of Jn < big
【问题讨论】:
-
@twasbrillig 发现了一个错误,包括更正 nmax -> nmax+1,然后我从错误应用的 mmax 中删除了 +1。
-
...我添加了说明。 n=0 指的是 J0 等,请记住第一个零不是原点的零(对于 n>0)。
标签: arrays python-2.7 numpy scipy bessel-functions