Questions tagged [set-operations]

Set operations as a branch of set theory which includes operations such as: Union, Intersection, Subset, Set Difference, Symmetrical Set Difference, and Set Equality.

References

88 questions
5
votes
1 answer

How do I manipulate CMake lists as sets?

In CMake, lists are used extensively. Sometimes you have two lists of items (strings, basically), and you want to consider their intersection, difference or union. Like in this case that just came up for me. How do I produce such intersection,…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
3 answers

How to get the symmetric difference of more than 2 lists?

I want to get all exclusive elements between all my lists. So if I have 3 lists like: list1 = [1, 3, 2] list2 = ["a", 1, 3] list3 = [2, 0] My output should be: ['a', 0] I tried to do symmetric differencing with all of the lists like: set(list1) ^…
Daniel
  • 53
  • 5
4
votes
5 answers

Efficient way to check high dimensional arrays are overlapped in two ndarray in Python

For example, I have two ndarrays, the shape of train_dataset is (10000, 28, 28) and the shape of val_dateset is (2000, 28, 28). Except for using iterations, is there any efficient way to use the numpy array functions to find the overlap between two…
Vicky
  • 1,465
  • 2
  • 12
  • 21
4
votes
1 answer

Python: how to convert a string array to a factor list

Python 2.7, numpy, create levels in the form of a list of factors. I have a data file which list independent variables, the last column indicates the class. For example: 2.34,4.23,0.001, ... ,56.44,2.0,"cloudy with a chance of rain" Using numpy, I…
ccc31807
  • 761
  • 8
  • 17
4
votes
2 answers

Assigning one set to another and when Clear is performed.Both the sets are getting cleared

1.Initially created two sets. 2.Added elements to one set. 3.Assigned one set to another. 4.If clear is called on one set,both the sets are getting cleared. Can anyone help in figuring out the problem? import java.util.HashSet; import…
Ranadheer
  • 75
  • 1
  • 5
3
votes
2 answers

Split column by separator and delete values contained in other values

I have a category column that is separated by ";". I.E Value: value <- "A > B > C; A > B > D; A > B > C > C1" It means: The current product belongs to category "A > B > C", to category "A > B > D" and to category "A > B > C > C1" If a category is…
Axel K
  • 191
  • 8
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
2 answers

Efficient bin-assignment in numpy

i have a very large 1D python array x of somewhat repeating numbers and along with it some data d of the same size. x = np.array([48531, 62312, 23345, 62312, 1567, ..., 23345, 23345]) d = np.array([0 , 1 , 2 , 3 , 4 , ..., 99998,…
rava
  • 183
  • 12
3
votes
6 answers

r return common rows for each value in a given column

assuming i have a dataframe that look like so: category type [1] A green [2] A purple [3] A orange [4] B yellow [5] B green [6] B orange [7] C green How do I get a list containing those types…
Tavi
  • 2,668
  • 11
  • 27
  • 41
3
votes
7 answers

How to find elements common in at least 2 vectors?

Say I have 5 vectors: a <- c(1,2,3) b <- c(2,3,4) c <- c(1,2,5,8) d <- c(2,3,4,6) e <- c(2,7,8,9) I know I can calculate the intersection between all of them by using Reduce() together with intersect(), like this: Reduce(intersect, list(a, b, c, d,…
enricoferrero
  • 2,249
  • 1
  • 23
  • 28
3
votes
2 answers

How to perform "a UNION b" when a and b are CTEs?

If I try to UNION (or INTERSECT or EXCEPT) a common table expression I get a syntax error near the UNION. If instead of using the CTE I put the query into the union directly, everything works as expected. I can work around this but for some more…
Gregory Arenius
  • 2,904
  • 5
  • 26
  • 47
3
votes
5 answers

Finding Set Complement in Unix

Given this two files: $ cat A.txt $ cat B.txt 3 11 5 1 1 12 2 3 4 2 I want to find lines number that is in A "BUT NOT" in B. What's the unix command for it? I tried this but…
neversaint
  • 60,904
  • 137
  • 310
  • 477
2
votes
4 answers

Compare two folders and copy/link unique entries to a new folder

How can I copy all unique files from two source folders to a new destination folder? As a set operation: How can I compute the difference between two folders?
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
2
votes
1 answer

R: How can I find the intersection of elements from two rows of a dataframe?

I'm just getting started with R, and I'm wondering how I can find the intersection of the elements from two rows of a dataframe. I tried intersect(thing[1,],thing[2,]) but it gave me a complete nonsense answer (something that definitely is not in…
2
votes
1 answer

Most efficient way to compute differences and intersection of two sets in Python

Let's say we have two sets s1 and s2. I require three different sets based on these two sets: Set of elements that exist in s1 but not in s2. Set of elements that exist in s2 but not in s1. Set of elements that exist in both s1 and s2. These could…
user999605
  • 35
  • 4