查询:
SELECT id_user
FROM Rating
Where id_movie=2
INTERSECT
SELECT id_user
FROM Rating
Where id_movie=3
Run Code Online (Sandbox Code Playgroud)
但我得到:
1064 - 您的SQL语法出错; 查看与您的MySQL服务器版本对应的手册,以便在第1行'INTERSECT SELECT
id_userFROM Ratingid_movie= 3 LIMIT 0,30'附近使用正确的语法
任何有解决方案?
我正在开发一种编程语言,我想提供一种Range数据类型,现在通常不是具有约束条件的int值对的列表.我说并不像通常那样,因为通常一个范围只是一对,但在我的情况下它不仅仅是,允许有例如(x,y)x < y
1 to 5, 7 to 11, 13 to 22
Run Code Online (Sandbox Code Playgroud)
全部包含在一个对象中.
我想提供两个函数来生成并集和两个范围的检测,这两个范围应该包含来自几个范围的最少数量的非重叠区间...例如
1 to 5 || 3 to 8 = 1 to 8
1 to 5 && 3 to 8 = 3 to 5
(1 to 3, 4 to 8) && 2 to 6 = (2 to 3, 4 to 6)
Run Code Online (Sandbox Code Playgroud)
||联合在哪里,&&是交叉点.
现在,他们的实现,如前所述,只是一个列表..我知道存在一个更合适的数据结构(区间树)但是现在我更关心从其他列表的联合/交集构建新列表.
哪些是实现这两个功能的最先进算法?
提前致谢
我需要代码/文本/谷歌关键字/其他资源来实现这个类.速度无关紧要.它应该适用于任何数量的维度.
class InfiniteVolume: # such as a point, line, plane, volume, 4d-volume
def __init__(self, points): # two points for line, three points for plane, etc.
self.points = points
assert all(len(p)==len(points[0]) for p in points)
def vdim(self): # Dimensions of the volume. For example 2.
return len(self.points)-1
def wdim(self): # Dimensions of the world. For example 3.
return len(self.points[0])
def __contains__(self, point):
# ???
def intersect(self, other):
assert self.wdim() == other.wdim()
# ???
Run Code Online (Sandbox Code Playgroud) 为了找到N个数组的交集,我有这个实现,这是非常低效的.我知道必须有一个算法来加速这个.
注意:myarray是包含我想要找到其交集的所有其他数组的数组.
var
i, j, k: integer;
myarray: Array of Array of integer;
intersection: array of integer;
for I := 0 to length(myarray)-1 do
begin
for J := 0 to length(myarray)-1 do
begin
if i = j then
continue;
for k := 0 to length(myarray[i])-1 do
begin
if myarray[i][j] = myarray[j][k] then
begin
setLength(intersection, length(intersection)+1);
intersection[length(intersection)-1] := myarray[j][k];
end;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我可以应用什么优化来加快速度?有更快的方法吗?
编辑:数组中的数据未排序.
arrays delphi optimization intersection multidimensional-array
我有一些圈子,我知道他们的X,Y和r.我想检查他们中的任何一个是否与其他任何人一致......检查的方法很简单:
r 1 + r 2 <sqrt((x 1 -x 2)2 +(y 1 -y 2)2)
但是我必须全部检查所有吗?它给了我O(n 2)的复杂性,我想避免这个:/
我使用了以下代码:http: //www.amphibian.com/blogstuff/collision.html.在html测试文件中,我将第一个三角形更改为
triangle1.addPoint({"x":-20, "y":-20});
triangle1.addPoint({"x":-20, "y":20});
triangle1.addPoint({"x":20, "y":20});
triangle1.addPoint({"x":20, "y":10});
triangle1.addPoint({"x":10, "y":10});
triangle1.addPoint({"x":10, "y":-20});
Run Code Online (Sandbox Code Playgroud)
现在,当我在穿过它之前移动另一个三角形内部这个形状给我错误的交叉点.知道哪里可能是问题?
目前我被困在试图找到三组的交集.现在这些集合实际上是我要转换成集合的列表,然后尝试找到它的交集.
这是我到目前为止所拥有的:
for list1 in masterlist:
list1 = thingList1
for list2 in masterlist:
list2 = thingList2
for list3 in masterlist:
list3 = thingList3
d3 = [set(thingList1), set(thingList2), set(thingList3)]
setmatches c = set.intersection(*map(set,d3))
print setmatches
Run Code Online (Sandbox Code Playgroud)
而且我正在
set([])
Script terminated.
Run Code Online (Sandbox Code Playgroud)
我知道有一个更简单,更好的方法来做到这一点,但我找不到一个......
编辑
好的,这就是我现在所拥有的.
setList=()
setList2=()
setList3=()
for list1 in masterlist:
setList=list1
for list2 in masterlist:
setList2=list2
for list3 in masterlist:
setList3=list3
setmatches=set(setList) & set(setList2) & set(setList3)
print setmatches
Run Code Online (Sandbox Code Playgroud)
仍然没有给我我正在寻找的东西:这是我确保在每个列表中的一个匹配.它给了我看起来像是所有套装的补充.
我试图使用霍夫变换计算光流算法的线之间的交点.但是,当我使用算法计算交叉点时,我没有得到我应该得到的分数.
我将Lines保存为我创建的类的实例ImageLine.这是我的交集方法的代码.
Point ImageLine::intersectionWith(ImageLine other)
{
float A2 = other.Y2() - other.Y1();
float B2 = other.X2() - other.X1();
float C2 = A2*other.X1() + B2*other.Y1();
float A1 = y2 - y1;
float B1 = x2 - x1;
float C1 = A1 * x1 + B1 * y1;
float det = A1*B2 - A2*B1;
if (det == 0)
{
return Point(-1,-1);
}
Point d = Point((B2 * C1 - B1 * C2) / det, -(A1 * C2 - A2 * …Run Code Online (Sandbox Code Playgroud) 我需要能够计算2个圆圈之间的交点.我确信总会有2个交叉点.不是1,不是0,不是无限,总是2.这是我想要做的图表:

这是我目前的尝试:
public static List<Vector2> intersect(Vector3 c1, Vector3 c2, float rad1, float rad2)
{
List<Vector2> rLp = new List<Vector2>();
float d = Vector2.Distance(c1, c2);
if (d > (rad1 + rad2))
return rLp;
else if (d == 0 && rad1 == rad2)
return rLp;
else if ((d + Mathf.Min(rad1, rad2)) < Mathf.Max(rad1, rad2))
return rLp;
else
{
float a = (rad1 * rad1 - rad2 * rad2 + d * d) / (2 * d);
float h = Mathf.Sqrt(rad1 * rad1 …Run Code Online (Sandbox Code Playgroud) 我有一个列表,列表中的每个元素都是一个数据框.
> df.list[[1]]
Change Diff VarName
1 10.433354 5.311973e-02 a
2 4.587958 1.517604e-02 b
3 4.566829 1.082679e-02 c
4 4.464458 1.345807e-02 d
5 4.146909 7.758011e-03 e
6 4.141556 1.416043e-02 f
> df.list[[2]]
Change Diff VarName
1 12.443354 5.311973e-02 j
2 3.587958 1.517604e-02 k
3 4.566829 1.082679e-02 a
4 4.464458 1.345807e-02 b
5 3.146909 7.758011e-03 d
6 2.141556 1.416043e-02 e
Run Code Online (Sandbox Code Playgroud)
我的列表长度是10,其中有10个数据帧.每个数据框有30个项目.我希望intersect每个数据框的前25个与另一个数据框最终得到所有数据框中最常见的项目.
这是我到目前为止所做的:
df1 <- df.list[[1]]$VarName
df2 <- df.list[[2]]$VarName
df3 <- df.list[[3]]$VarName
df4 <- df.list[[4]]$VarName
intersect(intersect(intersect(df1,df2), df3), df4)
Run Code Online (Sandbox Code Playgroud)
有没有使用dplyr …