为什么返回的函数数组是输入列表的两倍?

Yot*_*tam 0 python numpy scipy

我在python中创建了一个简单的函数:

def func(a,x):
  return a+x*2
Run Code Online (Sandbox Code Playgroud)

然后我称之为

x = [log(1),log(2),log(4),log(5),log(8)]
#Import y data from a file
free= curve_fit(func,np.array(x),np.array(y))[0][0]
yline = func(free,x)
Run Code Online (Sandbox Code Playgroud)

结果yline是两倍长,x并且每个元素在那里两次.

为什么会这样?

注意: 我正在导入numpy但不是scipy或curve_fit

eum*_*iro 5

x是一个列表,在func其中将"乘以2"(即其元素的数量加倍).

如果要将其乘以2(即乘以每个元素),请将其转换为np.array第一个:

x = [log(1),log(2),log(4),log(5),log(8)]
#Import y data from a file
free= curve_fit(func,np.array(x),np.array(y))[0][0]
yline = func(free, np.array(x))
Run Code Online (Sandbox Code Playgroud)