我正在努力用Python实现这个。有没有一种程序化的方法来实现这一点?我尝试用几个 for 循环来执行此操作,但我陷入了错误
SystemError: too many statically nested blocks
。
fs = {}
for i in range(100):
fs[i] = lamda x: x*i
for x1 in np.arange(0,1,.01):
for x2 in np.arange(0,1,.01):
....
for x100 in np.arange(0,1,.01):
for i in range(100):
exec("summ+= fs[i](x%i"%i)
当然很慢: “for i in range(100)”(1)部分达到100 * 100 * 100 * ... * 100 (100 '*100's) = 100 ^ 100;人们说 n^2 不好...... 无论如何,我会这样做:
- Put 100 values initialized with 0 into a list.
- for i = 0 to 100 ^ 100:
- go through the list and use the k-th value as the parameter for the k-th function. do the summing thing
- Add 0.1 to the n-th value in the list;
if this value is now == 1; set it to 0 and go to the (n+1)-th value and repeat this procedure until you reach the end of the list or one value is < 1.
Start with the first value in the list.
now you have your sum.