Questions tagged [set-intersection]

The intersection of two or more sets consists of the elements that those sets all have in common.

Set intersection is a mathematical operation defined upon sets.
The intersection of two or more sets is defined as the set of those elements that are present in all sets.

For example, let A = { 2, 3, 4 } and B = { 2, 4, 5 }.
The intersection of A and B is what the set of elements that A and B have in common: { 2, 4 }.
The symbol for intersection is ∩, so in our example we would write A ∩ B = { 2, 4 }

276 questions
2
votes
4 answers

Simultaneous Union and Intersection between two maps in C++

While doing a college project I came upon the following problem: I have two maps (Kmer1 and Kmer2) which are composed by a string(key) and a int(value). I have to calculate the distance which follows this formula [1-(I/U)]*100 Where... ...U =…
Pauete Galopa
  • 153
  • 1
  • 1
  • 9
2
votes
2 answers

Counting length of intersection of a list with pandas column of lists

I have a list of unique random integers and a dataframe with a column of lists, like below: >>> panel [1, 10, 9, 5, 6] >>> df col1 0 [1, 5] 1 [2, 3, 4] 2 [9, 10, 6] The output I would like to have is the length of the…
Miguel Wang
  • 183
  • 1
  • 12
2
votes
3 answers

Why is the compiler giving me an error on my set_intersection?

I have a class which has two attributes : set< int > ens1_; set< int > ens2_; Now, I have a method which finds the intersection between these two sets. Here is what I wrote in my method: set< int > ens; set< int >::iterator it; it =…
Etienne Noël
  • 5,988
  • 6
  • 48
  • 75
2
votes
4 answers

Lisp/Intersection of Lists

Hello i am trying to create a function in common-lisp that takes two lists, and output their intersections, assuming there is no repetition in each list without using intersection function. It seems that it is not working. Can anyone help? (defun…
user9574667
2
votes
1 answer

std::set_intersection with custom comparator

I'm trying to understand the syntax for std::set_intersection when using a custom comparator. I'm trying to get the intersection of sets one and two, which should result in a set (intersect) containing only element f2. I get error: passing ‘const…
Elliott
  • 2,603
  • 2
  • 18
  • 35
2
votes
1 answer

How to lambdify an Intersection

I am inverting a function with the invert_real from sympy.solvers.solveset, because neither solve nor solveset can do it for some reason. The result is an Intersection and seems to be correct. I now want to use it for numeric calculations. When I…
Noldi
  • 23
  • 2
2
votes
1 answer

server side set intersection in mongodb

In an application I am working on, a requirement is to do massive set intersection, to the tune of 10-1,000,000 items or so. The items that we are intersecting are simply ObjectId's. So for instance there is a boxes document and inside the boxes…
spotman
  • 857
  • 7
  • 11
2
votes
3 answers

Curious question : What algorithm does STL set_intersect implement?

I spent a considerable amount of time coding in Baeza-Yates' fast set intersection algorithm for one of my apps. While I did marginally out-do the STL set_intersect, the fact that I required the resultant set to be sorted removed any time I had…
vishakad
  • 567
  • 1
  • 6
  • 7
2
votes
3 answers

jq select elements with array not containing string

Now, this is somewhat similar to jq: select only an array which contains element A but not element B but it somehow doesn't work for me (which is likely my fault)... ;-) So here's what we have: [ { "employeeType": "student", "cn":…
Thomas
  • 173
  • 2
  • 9
2
votes
1 answer

Implementing intersection operator for a set-like class in Python

I'm trying to implement a wrapper class which should ideally allow me to get the intersection of its elements using the notation: a & b Is there a specific method that I can implement to achieve this? (I know that the individual elements need to…
ws6079
  • 343
  • 2
  • 11
2
votes
1 answer

Plot the intersection in every two list elements

Given a list of 16 elements, where each element is a named numeric vector, I want to plot the length of the intersection of names between every 2 elements. That is; the intersection of element 1 with element 2, that of element 3 with element 4, etc.…
Forest
  • 721
  • 1
  • 8
  • 14
2
votes
1 answer

Spark: How to efficiently have intersections preserving duplicates (in Scala)?

I have 2 RDDs, each of which is a set of strings containing duplicates. I want to find the intersection of the two sets preserving duplicates. Example: RDD1 : a, b, b, c, c, c, c RDD2 : a, a, b, c, c The intersection I want is the set a, b, c, c…
TCSGrad
  • 11,898
  • 14
  • 49
  • 70
2
votes
2 answers

How do I find the intersection of 2 sets?

What is the most efficient way to create a subset from 2 sets that contains values from both of them? Any C++ STL library can be used to solve this (without Boost library if possible): Set A = {2, 3, 5, 7, 11, ...} Set B = {1, 3, 5, 7, 9, 11,…
Striker
  • 507
  • 4
  • 11
2
votes
1 answer

Finding the intersect of two arrays in Fortran

I'm trying to generate the intersect of two 1-D arrays in Fortran. The intent is to use this intersection as a mask in maxloc so that I can pull the max few elements from one array into another (behavior analogous to repeated root removal in a max…
River
  • 8,585
  • 14
  • 54
  • 67
2
votes
2 answers

intersection of n vectors

I'm new to programming and I've recently come across an issue with finding the intersection of n vectors, (int vectors) that have sorted ints. The approach that I came up with has a complexity of O(n^2) and I am using the std::set_intersect…
SnG
  • 362
  • 1
  • 5
  • 18