标签: intersect

相交()相反

Intersect可用于查找两个集合之间的匹配,如下所示:

// Assign two arrays.
int[] array1 = { 1, 2, 3 };
int[] array2 = { 2, 3, 4 };
// Call Intersect extension method.
var intersect = array1.Intersect(array2);
// Write intersection to screen.
foreach (int value in intersect)
{
    Console.WriteLine(value); // Output: 2, 3
}
Run Code Online (Sandbox Code Playgroud)

然而,我想要实现的是相反的,我想列出比较两个集合时缺少的项目:

// Assign two arrays.
int[] array1 = { 1, 2, 3 };
int[] array2 = { 2, 3, 4 };
// Call "NonIntersect" extension method.
var intersect = array1.NonIntersect(array2); // …
Run Code Online (Sandbox Code Playgroud)

.net c# collections intersect

264
推荐指数
5
解决办法
10万
查看次数

替代MySQL中的Intersect

我需要在MySQL中实现以下查询.

(select * from emovis_reporting where (id=3 and cut_name= '?????' and cut_name='??') ) 
intersect
( select * from emovis_reporting where (id=3) and ( cut_name='?????' or cut_name='??') )
Run Code Online (Sandbox Code Playgroud)

我知道相交不在MySQL中.所以我需要另一种方式.请指导我.

mysql intersect

60
推荐指数
4
解决办法
10万
查看次数

在两个Pandas数据帧中查找公共行(交集)

假设我有这样的格式(叫他们两个dataframes df1df2):

+------------------------+------------------------+--------+
|        user_id         |      business_id       | rating |
+------------------------+------------------------+--------+
| rLtl8ZkDX5vH5nAx9C3q5Q | eIxSLxzIlfExI6vgAbn2JA |      4 |
| C6IOtaaYdLIT5fWd7ZYIuA | eIxSLxzIlfExI6vgAbn2JA |      5 |
| mlBC3pN9GXlUUfQi1qBBZA | KoIRdcIfh3XWxiCeV1BDmA |      3 |
+------------------------+------------------------+--------+
Run Code Online (Sandbox Code Playgroud)

我希望得到的是有一个共同的所有行的数据帧user_iddf1df2.(即,如果user_id是在两个df1df2,在输出中包括数据帧的两行)

我可以想出很多方法来解决这个问题,但它们都让我感到笨拙.例如,我们可以user_id在每个数据帧中找到所有唯一的s,创建一组,找到它们的交集,用结果集过滤两个数据帧并连接两个过滤的数据帧.

也许这是最好的方法,但我知道熊猫很聪明.有更简单的方法吗?我看过了,merge但我认为这不是我需要的.

python dataframe intersect pandas

43
推荐指数
3
解决办法
7万
查看次数

如何在Python中计算两条线的交点?

我有两条线在一点交叉.我知道这两行的终点.如何计算Python中的交叉点?

# Given these endpoints
#line 1
A = [X, Y]
B = [X, Y]

#line 2
C = [X, Y]
D = [X, Y]

# Compute this:
point_of_intersection = [X, Y]
Run Code Online (Sandbox Code Playgroud)

python geometry line intersect

41
推荐指数
7
解决办法
8万
查看次数

如何检查Ruby数组是否包含多个值之一?

我有两个Ruby数组,我需要看看它们是否有任何共同的值.我可以循环遍历一个数组中的每个值,并在另一个数组中包含?(),但我确信有更好的方法.它是什么?(这些数组都包含字符串.)

谢谢.

ruby arrays string intersect

31
推荐指数
3
解决办法
2万
查看次数

计算2个列表中存在的项目

我有两个int型ListList AList B.我要检查多少项目List A是那里List B.我能够做到这一点,但是foreach因为优化是我的代码中的主要目标,所以我可以避免这种有效方式.

List<int> A = new List<int>;
List<int> B = new List<int>;
// Some logic....item added in both lists. Then

foreach(var item in A)
{
    if (B.Contains(item))
    {
        // Subtract number of duplicates
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用IntersectAny,但是返回bool所以我无法完全应用它们.

c# linq list count intersect

22
推荐指数
3
解决办法
5025
查看次数

21
推荐指数
3
解决办法
2万
查看次数

C#Linq与对象的一部分相交/除外

我上课了:

class ThisClass
{
  private string a {get; set;}
  private string b {get; set;}
}
Run Code Online (Sandbox Code Playgroud)

我想使用Linq的Intersect和Except方法,即:

private List<ThisClass> foo = new List<ThisClass>();
private List<ThisClass> bar = new List<ThisClass>();
Run Code Online (Sandbox Code Playgroud)

然后我分别填写两个列表.我想做,例如(我知道这是不对的,只是伪代码),如下:

foo[a].Intersect(bar[a]);
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

c# linq except intersect

21
推荐指数
3
解决办法
2万
查看次数

使用Linq与自定义IEqualityComparer相交

长话短说:我有2个对象集合.一个包含好的值(让我们称之为"好"),其他默认值(先生"默认").我希望联盟的相交在良好和默认之间,以及默认.换句话说:相交(联合(良好,默认),默认).有人可能认为它解析为默认值,但这里是棘手的:我使用自定义IEqualityComparer.

我得到了以下课程:

class MyClass
{
    public string MyString1;
    public string MyString2;
    public string MyString3;
}

class MyEqualityComparer : IEqualityComparer<MyClass>
{
    public bool Equals(MyClass item1, MyClass item2)
    {
        if(item1 == null && item2 == null)
            return true;
        else if((item1 != null && item2 == null) ||
                (item1 == null && item2 != null))
            return false;

        return item1.MyString1.Equals(item2.MyString1) &&
               item1.MyString2.Equals(item2.MyString2);
    }

    public int GetHashCode(MyClass item)
    {
        return new { item.MyString1, item.MyString2 }.GetHashCode();
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我的收藏品Good和Default集合的特征:

默认值:它是一个很大的集合,包含所有想要的{MyString1,MyString2}对,但是你可以猜测,MyString3值是默认值.

好:它是一个较小的集合,主要包含默认集合中的项目,但具有一些好的MyString3值.它还有一些{MyString1,MyString2},它们位于想要的集合之外.

我想要做的是:只获取Good中默认的项目,但将Default中的其他项目添加到默认项目中.

这是我认为最好的尝试:

HalfWantedResult = Good.Union(Default, …
Run Code Online (Sandbox Code Playgroud)

c# linq intersection intersect

14
推荐指数
2
解决办法
2万
查看次数

c#词典相交

我有关于Linq/Lambda的问题以及以下问题:

我有两个词典,主要和次要......这两个词典被定义为Key = string,Value = int.如果KEYS与辅助字典相交,我需要修剪主字典.

即:

primaryDict = ["thing1", 33] ["thing2", 24] ["thing3", 21] ["thing4", 17] ["thing5", 12]

secondaryDict = ["thing1", 22] ["thing3", 20] ["thing4", 19] ["thing7", 17] ["thing9", 10]

resultDict = ["thing1", 33] ["thing3", 21] ["thing4", 17]
Run Code Online (Sandbox Code Playgroud)

我的尝试:

resultDict = primaryDict.Keys.Intersect(secondaryDict.Keys).ToDictionary(t => t.Key, t.Value);
Run Code Online (Sandbox Code Playgroud)

这显然不起作用,因为primaryDict.Keys.Intersect返回一个键列表...我将如何重新建立一个新词典,或者配对主词典?任何帮助,将不胜感激.

c# dictionary key intersect

14
推荐指数
1
解决办法
1万
查看次数