Perform the following Standard Set Operations using Numpy Array. array1 = np.array([[10, 20, 30], [14, 24, 36]]) array2 = np.array([[20, 40, 50], [24, 34, 46]]). Data science using Python in Anaconda - Jupyter
Question
1. Find the union of two arrays
2. Find the intersection of two arrays
3. Find the set difference of two arrays
Program: -
import numpy as np
array1 = np.array([[10, 20, 30], [14, 24, 36]])
array2 = np.array([[20, 40, 50], [24, 34, 46]])
print("union of two arrays :- \n",np.union1d(array1,array2))
print("intersection of two arrays :- \n",np.intersect1d(array1,array2))
print("set difference of two arrays :- \n",np.setdiff1d(array1,array2))
Output: -
union of two arrays :-
[10 14 20 24 30 34 36 40 46 50]
intersection of two arrays :-
[20 24]
set difference of two arrays :-
[10 14 30 36]