这是我的代码为什么`pprint()`在Sympy中没有用于for循环?
14 def sum(output):
15 result = 0
16 for x, w in zip(output[0], output[1]):
17 result+=w*np.exp(-((((b-a)/2.0)*x)+((a+b)/2.0))**2)
18 pprint(w*exp(-((((b-a)/2.0)*x)+((a+b)/2.0))**2))
19 return ((b-a)/2.0)*result
对于此代码,如果我调用一个函数sum
我的终端输出打印:
0.548543700179284
0.6
0.692267362730138
0.0
0.252818105473090
0.6
但如果
14 def sum(output):
15 result = 0
16 for x, w in zip(output[0], output[1]):
17 result+=w*np.exp(-((((b-a)/2.0)*x)+((a+b)/2.0))**2)
18 return ((b-a)/2.0)*result
19
20 pprint(w*np.exp(-((((b-a)/2.0)*x)+((a+b)/2.0))**2))
它将打印一个美丽方程(我的意思是pprint()它的工作!)。
为什么第一个代码不能像第二个代码一样打印漂亮的方程?
请加什么'x'和'w'被定义为在你的第二个例子。 –
@NilsWerner x和w它只是列表的元素。 – fronthem
和'sum()'之外? –