python如何知道哪个3点是一条线
我找到了一些使用三角形区域的解决方案来查找线条,但这不是我需要的,因为在进一步的步骤中,这不是解决我的问题的解决方案。
我一直在嵌套循环进行工作,在那里我看到点0和1之间的斜率,如果价格相同,我找到了一个线,就会给我下一个点的预测(每个点的价格)。
现在,我是第一个循环回到我的斜坡,但是我正在为第二个循环而努力以获得EXP_PRICE比较...关于如何简单地找到此行的任何想法?
initial_data = {'index': [4, 17, 24, 36, 42],
'High': [805.000000, 1094.939941, 1243.489990, 1201.949951, 1172.839966],
}
test = pd.DataFrame(initial_data)
slope_data = {'index': [4, 17, 24, 36, 42],
'High': [805.000000, 1094.939941, 1243.489990, 1518.7, 1172.839966],
'Slope': [0, 22.30307, 21.22144, 22.93417, -57.64334],
}
嵌套循环是一种选择,但也许是最简单的换行方法,即知道哪个是一条线?
for i in range(len(test)):
#test.loc[:,'slope'] = (test.loc[i,'High'] - test.loc[i,'High']) / (test.loc[i,'index'] - test.loc[i,'index'])
test['slope'] = round((test['High']-test['High'].shift(1)) / (test['index']-test['index'].shift(1)),8)
print(test)
for j in range(len(test)):
exp_price = (test['High'].shift(1) + (test['slope']*(test['index']-test['index'].shift(j))))
#If exp_price of j equals High of i (+- 0,5% tolerance) I've found a line!
# print(values)
test['result'] = values
print(test)
请注意,我想将0,1与2、3和4。0、2
与3、4。0、3
与
4.1、2与3、4。
等等相提并论。这就是为什么我尝试使用嵌套循环。
I've found some solutions using the triangle area to find lines but It's not what I need because in further steps will not be a solution for my problem.
I've been working on a nested loop where I see the slope between point 0 and 1 and gives me a projection for next points (expexcted price for each point) If the price is the same +- tolerance I have found a line.
Now I've the first loop returning me Slopes but I'm struggling with the second loop to get the exp_price comparision... Any idea on how to find this lines simple?
initial_data = {'index': [4, 17, 24, 36, 42],
'High': [805.000000, 1094.939941, 1243.489990, 1201.949951, 1172.839966],
}
test = pd.DataFrame(initial_data)
slope_data = {'index': [4, 17, 24, 36, 42],
'High': [805.000000, 1094.939941, 1243.489990, 1518.7, 1172.839966],
'Slope': [0, 22.30307, 21.22144, 22.93417, -57.64334],
}
The nested loop is an option, but maybe is an easiest way vecotrizing to know which 3 are a line?
for i in range(len(test)):
#test.loc[:,'slope'] = (test.loc[i,'High'] - test.loc[i,'High']) / (test.loc[i,'index'] - test.loc[i,'index'])
test['slope'] = round((test['High']-test['High'].shift(1)) / (test['index']-test['index'].shift(1)),8)
print(test)
for j in range(len(test)):
exp_price = (test['High'].shift(1) + (test['slope']*(test['index']-test['index'].shift(j))))
#If exp_price of j equals High of i (+- 0,5% tolerance) I've found a line!
# print(values)
test['result'] = values
print(test)
Note I want to compare 0,1 with 2, 3 and 4.
0, 2 with 3, 4.
0, 3 with 4.
1, 2 with 3, 4.
and so on... That's why I try to use the nested loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行此操作:
输出:
说明:
point1,point2,cant2,cantute
;对于问题中的示例,这是(0,1,2),(0,1,3),(0,1,4),(0,2,3),(0,2,4),( 0,3,4),(1,2,3),(1,2,4),(1,3,4),(2,3,4)Projy
,这是候选人的预计y坐标X COORD,以及列inline
,指示candy
在给定的公差内是否匹配projy
,这意味着候选人确实是与两个点联合。中间结果:
You can do this:
Output:
Explanation:
point1, point2, candidate
; for the example in the question, this is (0,1,2), (0,1,3), (0,1,4), (0,2,3), (0,2,4), (0,3,4), (1,2,3), (1,2,4), (1,3,4), (2,3,4)linex, liney, candx, candy, slope
which are the x, y coords of one of the points on the line, the coords of the candidate point, and the slope of the lineprojy
which is the projected y coord for the candidate's x coord, and also the columninline
which indicates whethercandy
matchesprojy
within a given tolerance, meaning the candidate is indeed collinear with the two points.Intermediate results: