這是我的代碼爲什麼`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()'之外? –