ufunc Set Operations
Learn all about ufunc Set Operations in this comprehensive tutorial.
- •A set in mathematics is a collection of unique elements.
- •We can use NumPy's unique() method to find unique elements from any array.
- •To find the unique values of two arrays, use the union1d() method.
- •To find only the values that are present in both arrays, use the intersect1d() method.
- •To find only the values in the first set that is NOT present in the seconds set, use the setdiff1d() method.
- •To find only the values that are NOT present in BOTH sets, use the setxor1d() method.
What is a Set
A set in mathematics is a collection of unique elements.
Sets are used for operations involving frequent intersection, union and difference operations.
Create Sets in NumPy
We can use NumPy's unique() method to find unique elements from any array. E.g. create a set array, but remember that the set arrays should only be 1-D arrays.
Finding Union
To find the unique values of two arrays, use the union1d() method.
Finding Intersection
To find only the values that are present in both arrays, use the intersect1d() method.
Finding Difference
To find only the values in the first set that is NOT present in the seconds set, use the setdiff1d() method.
Finding Symmetric Difference
To find only the values that are NOT present in BOTH sets, use the setxor1d() method.
Module quiz
2 questionsWhich of the following is true about ufunc Set Operations?
What is the most common pitfall when working with ufunc Set Operations?
Answer all questions to submit.