我正在尝试计算 function 的值f_integ
,这是 functionf
从 0 到x_v
.
f = lambda x : x + 1
def f_integ(x_array):
int_result = np.zeros_like(x_array)
indexes = np.shape(x_array)[0]
for ind in range(indexes):
x_v = x_array[ind]
int_result[ind] = integ.quad(f, 0.0, x_v)[0]
return int_result
C = f_integ(1)
print "C", C
当我运行它时,我收到以下错误:
Traceback (most recent call last):
File "untitled.py", line 117, in <module>
C = f_integ(1)
File "scr1.py", line 110, in f_integ
indexes = np.shape(x_array)[0]
IndexError: tuple index out of range
我知道quad()
返回一个元组,但我不知道如何将一个数字作为参数放在积分结果中。我是Python新手,请帮忙。