Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

ufunc Set Operations

What is a Set

In mathematics, a set is a collection of distinct elements. Sets are utilized for operations that frequently involve intersections, unions, and differences.

Create Sets in NumPy

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.

Example

Convert the following array containing repeated elements into a set.

import numpy as np

arr = np.array([1112345567])

x = np.unique(arr)

print(x)