Questions tagged [set-difference]

The difference between two sets A and B consists of all elements that are in A but not in B.

Set difference is a mathematical operation defined on sets. It is also known as the relative complement of B with respect to A.
If we have two sets, say A and B, their difference A - B is the set of all elements that are in A but not in B.

Several programming languages have built-in features to remove a collection of elements from another collection of elements. When both collections are sets (meaning each element can occur at most once per collection and the order does not matter), this implements set difference.

Source: Wikipedia

197 questions
11
votes
3 answers

difference of two sets of intervals

i'm trying to write some code to calculate the difference of two sets of intervals A - B , Interval endpoints are integers , but i'm strugling to come with efficient solution , any suggestion would be much appreciated example : [(1, 4), (7, 9)] -…
10
votes
3 answers

JQ: setdiff of two arrays

If I have an object with two arrays containing unique values in it {"all":["A","B","C","ABC"],"some":["B","C"]} How can I find .all - .some? In this case I am looking for ["A","ABC"]
Jon
  • 1,785
  • 2
  • 19
  • 33
10
votes
4 answers

Function to find symmetric difference (opposite of intersection) in R?

The Problem I have two string vectors of different lengths. Each vector has a different set of strings. I want to find the strings that are in one vector but not in both; that is, the symmetric difference. Analysis I looked at the function setdiff,…
Gyan Veda
  • 6,309
  • 11
  • 41
  • 66
10
votes
2 answers

std::set_difference on list container

I'm trying to call the set_difference function, and put the result on a std::list. In theory, it is possible to do this on any sorted container, right? list v; list l1; list l2; list::iterator…
Dynelight
  • 2,072
  • 4
  • 25
  • 50
9
votes
3 answers

How do I find the keys in one dictionary that do not have a counterpart in another dictionary?

In Python, how do I find the keys in one dictionary that do not have a counterpart in another dictionary? The practical problem is that I have a dictionary of people that enrolled and a dictionary with their daily participation and I am trying to…
user3426752
  • 415
  • 1
  • 8
  • 17
8
votes
1 answer

How to use Shapely for subtracting two polygons

I am not really sure how to explain this but I have 2 polygons, Polygon1 and Polygon2. These polygons overlapped with each other. How to do I get Polygon2 using Shapely without the P from Polygon1.
simple guy
  • 633
  • 1
  • 6
  • 19
8
votes
5 answers

How to calculate difference between two sets in emacs lisp,the sets should be lists

How to calculate the difference between two sets in Emacs Lisp? The sets should be lists. The programm should be very simple and short, or else I won't understand it. I'm a newbee. Thx
user1438363
  • 81
  • 1
  • 3
7
votes
4 answers

Not in In SQL statement?

I have set of ids in excel around 5000 and in the table I have ids around 30000. If I use 'In' condition in SQL statment I am getting around 4300 ids from what ever I have ids in Excel. But If I use 'Not In' with Excel id. I have getting around…
James123
  • 11,184
  • 66
  • 189
  • 343
6
votes
2 answers

How do I delete the intersection of sets A and B from A without sorting in MATLAB?

Two matrices, A and B: A = [1 2 3 9 7 5 4 9 4 1 4 7] B = [1 2 3 1 4 7] All rows of matrix B are members of matrix A. I wish to delete the common rows of A and B from A without sorting. I have tried setdiff() but this sorts the…
Darren J. Fitzpatrick
  • 7,159
  • 14
  • 45
  • 49
6
votes
4 answers

Concise way to find "key" difference between 2 dictionaries?

I needed to compare 2 dictionaries to find the set of keys in one dictionary which was not in the other. I know that Python set objects support: set3=set1-set2 but I can't do: dict3=dict1-dict2 or: missingKeys=dict1.keys()-dict2.keys() (I was a…
Sam Goldberg
  • 6,711
  • 8
  • 52
  • 85
5
votes
1 answer

c++ list not resizing after set difference

Consider the following code: #include #include #include int main() { std::list v = {1, 3, 4}; std::cout << v.size() << std::endl; v.resize(0); std::cout << v.size() << std::endl; } after compiling…
5
votes
4 answers

Can't seem to get my head around the 'list difference' (\\) operator

I have heard the term 'list difference' (\\) operator in Haskell but still don't quite know how to get my head around it. Any examples or ideas?
maclunian
  • 7,893
  • 10
  • 37
  • 45
5
votes
2 answers

How to get (unordered) set difference or symmetric difference in C++?

I can't infer I can use std::set_difference from documentation, because it says sets should be ordered, which means they are not sets, but lists. Also all examples are about ordered lists, not sets. How to know the truth?
Dims
  • 47,675
  • 117
  • 331
  • 600
5
votes
3 answers

All-to-all setdiff on two numeric vectors with a numeric threshold for accepting matches

What I want to do is more or less a combination of the problems discussed in the two following threads: Perform non-pairwise all-to-all comparisons between two unordered character vectors --- The opposite of intersect --- all-to-all setdiff Merge…
vivoru
  • 53
  • 4
5
votes
2 answers

Perform non-pairwise all-to-all comparisons between two unordered character vectors --- The opposite of intersect --- all-to-all setdiff

EXAMPLE DATA v1 <- c("E82391", "X2329323", "C239923", "E1211", "N23932", "F93249232", "X93201", "X9023111", "O92311", "9000F", "K9232932", "L9232932", "X02311111") v2 <- c("L9232932", "C239923", "E1211", "E82391", "F93249232", "U82832") PROBLEM I…
paropunam
  • 488
  • 2
  • 11
1
2
3
13 14