Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Finding Difference

To obtain only the values in the first set that are not present in the second set, use the setdiff1d() method.

Example

Calculate the difference of set1 from set2.

import numpy as np

set1 = np.array([1234])
set2 = np.array([3456])

newarr = np.setdiff1d(set1, set2, assume_unique=True)

print(newarr)

Finding Symmetric Difference

To retrieve only the values that are not present in both sets, use the setxor1d() method.

Example

Calculate the symmetric difference between set1 and set2.

import numpy as np

set1 = np.array([1234])
set2 = np.array([3456])

newarr = np.setxor1d(set1, set2, assume_unique=True)

print(newarr)