我在dictionary对象中有x和y数据,格式为{'item1':(x,y),'item2':(x,y)….}其中每个x和y值都是100个数字的列表。 对于每个键,我的x值从0到50。我只想根据x>;=10和x<;=20的数据拟合一条直线。 这就是我要做的。。。在
for key,value in Dict.iteritems():
#Get x,y values from each key in turn.
[x,y] = Dict.get(key)
# Extract just the x values in range.
xFit = [i for i in x if (i>=10 and i<=20)]
<< yFit = Get the corresponding y values for xFit >>
p = polyfit(xFit, yFit, 1)
有没有一种很好的方法可以在所需的范围内为[x,y]数据拟合一条线? 提前谢谢你的帮助。在
您可以在},这将使使用花式索引的条件切片更容易:
np.array
中同时转换x
和{相关问题 更多 >
编程相关推荐