这是我的代码
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() 它有效!)。
为什么第一个代码不能像第二个代码一样打印出漂亮的方程式?