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
3
votes
1 answer

Problem with upset plot intersection numbers

I have four sets A, B, C and D like below: A <- c("ENSG00000103472", "ENSG00000130600", "ENSG00000177335", "ENSG00000177337", "ENSG00000178977", "ENSG00000180139", "ENSG00000180539", "ENSG00000187621", "ENSG00000188511", "ENSG00000197099",…
beginner
  • 1,059
  • 8
  • 23
3
votes
5 answers

`pd.concat` with `join=='inner'` doesn't produce intersection of pandas dataframes

I am trying to extract common rows from several dataframes using pd.concat: >>> import numpy as np >>> import pandas as pd >>> x = np.random.random(size=(5, 3)) >>> df1 = pd.DataFrame(x) >>> df2 = pd.DataFrame(x[1:3]) >>> df3 =…
Peaceful
  • 4,920
  • 15
  • 54
  • 79
3
votes
2 answers

Match rows of a matrix to the rows of another, regardless of the column order?

I have two matrices, and I need to find if the two-column sets in one matrix appear in the other matrix without regard for the order (A:B = B:A). As an example, here are two matrices: X <- matrix(c(23, 33, 4, 21, 5, 27, 47, 39, 37, 8, 30, 42, 59,…
3
votes
3 answers

Intersection of two std::unordered_map

I have two std::unordered_map std::unordered_map mp1; std::unordered_map mp2; I need to find the intersection of key-value pairs and store it in another map of the form. std::unordered_map mp; How can i do this??
3
votes
1 answer

Set intersection in Tensorflow

I want to check if any of a set of given values are contained in a sparse tensor. The sparse tensor is called labels and has just one dimension containing a list of ids. In the end this seems like a simple set intersection problem, so I tried…
jaime
  • 520
  • 5
  • 15
3
votes
3 answers

writing a AND query for to find matching documents within a dataset (python)

I am trying to construct a function called 'and_query' that takes as input a single string, consisting of one or more words, such that the function returns a list of matching documents for the words being in the abstracts of the documents. First, I…
3
votes
1 answer

Set operations in Appengine datastore

I assume there's no good way to do so, but if you had to, how would you implement set operations on Appengine's datastore? For example given two collections of integers, how would you store them in the datastore to get a good performance for…
r0u1i
  • 3,526
  • 6
  • 28
  • 36
3
votes
4 answers

Find files with same initial part of the name in two folders

I used listdir to read the files in two folders: from os import listdir list_1 = [file for file in listdir("./folder1/") if file.endswith(".csv")] list_2 = [file for file in listdir("./folder2/") if file.endswith(".json")] and now I have two…
DeltaIV
  • 4,773
  • 12
  • 39
  • 86
3
votes
3 answers

Find intersection sets between list of sets

The following question is on python 3.6. Suppose I have lists of sets, for example L1 = [{2,7},{2,7,8},{2,3,6,7},{1,2,4,5,7}] L2 = [{3,6},{1,3,4,6,7},{2,3,5,6,8}] L3 = [{2,5,7,8},{1,2,3,5,7,8}, {2,4,5,6,7,8}] I need to find all…
cdt
  • 85
  • 10
3
votes
4 answers

Check if two dictionaries are disjoint

Is there an easier/faster way to find out if two dictionaries are disjoint than calculating their intersection? For the intersection I found this answer, so the disjoint-test would look like this: def dicts_disjoint(a, b): keys_a =…
Johannes
  • 3,300
  • 2
  • 20
  • 35
3
votes
0 answers

Python: Create a matrix of the length of the intersection of two lists whose elements are sets of numbers

I'm using Python 3.5 and I'm wondering if there is a more efficient way to do this. I have two lists (list1 and list2). Each element in each list is a set of numbers. In the example below, list1 is basically a 1x4 "matrix" and list2 is a 1x3…
pdanese
  • 2,187
  • 4
  • 15
  • 21
3
votes
1 answer

How to find intersection or subset of two CSV files

I have 2 CSV files containing two columns and a large number of rows. The first column is the id, and the second is the set of paired values. e.g.: CSV1: 1 {[1,2],[1,4],[5,6],[3,1]} 2 {[2,4] ,[6,3], [8,3]} 3 {[3,2], [5,2], [3,5]} CSV2: 1 {[2,4]…
A S
  • 103
  • 1
  • 2
  • 5
3
votes
2 answers

Combining discrete and/or overlapping time sequences from lists

I have 2 lists of ordered times which are the start/stop times for ServiceA and ServiceB, respectively. I want to combine the lists in one list containing the start and stop times (in order) of when at least 1 of the services was running. (Both…
D.C.
  • 31
  • 3
3
votes
3 answers

Check intersection between two strings in python

I'm trying to check intersection between two strings using Python. I defined this function: def check(s1,s2): word_array = set.intersection(set(s1.split(" ")), set(s2.split(" "))) n_of_words = len(word_array) return n_of_words It works…
JJack_
  • 859
  • 9
  • 30
3
votes
1 answer

Multiple intersection of lists

I have 4 lists a <- list(1,2,3,4) b <- list(5,6,7,8) c <- list(7,9,0) d <- list(12,14) I would like to know which of the lists have elements in common. In this example, lists b and c have the element 7 in common. A brute force approach would be to…
Dinesh
  • 2,194
  • 3
  • 30
  • 52