检查两个图是否相交?

发布于 2025-01-21 06:28:28 字数 327 浏览 2 评论 0 原文

每当两个图相交时,我都想打电话 这是 img

这是数据

I want to make a call whenever the two graphs get intersected
Here's img

here's the data https://jpn698dhc9.execute-api.us-east-1.amazonaws.com/prod/v2/historical?symbol=%22degods%22

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2025-01-28 06:28:28

如果您有两个时间序列为同等索引 pd.series 对象,则可以简单地减去它们,确定差异的符号(告诉您哪个更高),确定这些标志的差异时间(告诉您两者的顺序是否已更改),并每当这些符号差异不为零(告诉您顺序有变化,即图表的交集)。以下代码计算其各自的前任之间的所有时间段的索引。

import numpy as np
import pandas as pd
s1 = pd.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
s2 = pd.Series([0.0, 1.3, 2.6, 3.9, 5.2, 6.5])
diffs = np.sign(s1 - s2).diff()[1:]
indices = diffs[diffs.ne(0)].index.values

If you have two time series as equally-indexed pd.Series objects, you can simply subtract them, determine the signs of the differences (which tells you which is higher), determine the differences of these signs over time (which tells you whether or not the order of the two has changed) and look at whenever those sign differences are non-zero (which tells you that there was a change in the order, i.e. an intersection of the graph). The following code computes the indices of all timesteps between whose and their respective predecessors there were intersections:

import numpy as np
import pandas as pd
s1 = pd.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
s2 = pd.Series([0.0, 1.3, 2.6, 3.9, 5.2, 6.5])
diffs = np.sign(s1 - s2).diff()[1:]
indices = diffs[diffs.ne(0)].index.values
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文