In mathematics, a set is a collection of distinct elements. Sets are utilized for operations that frequently involve intersections, unions, and differences.
We can use NumPy’s unique() method to extract unique elements from any array. For example, create a set array, keeping in mind that the set arrays should only be one-dimensional.
Convert the following array containing repeated elements into a set.
import numpy as np arr = np.array([1, 1, 1, 2, 3, 4, 5, 5, 6, 7]) x = np.unique(arr) print(x) |