{ "cells": [ { "cell_type": "markdown", "id": "54d7b273", "metadata": {}, "source": [ "# `unique` and other set logic\n", "\n", "NumPy has some basic set operations for one-dimensional `ndarray`. A commonly used one is [numpy.unique](https://numpy.org/doc/stable/reference/generated/numpy.unique.html), which returns the sorted unique values in an array:" ] }, { "cell_type": "code", "execution_count": 1, "id": "f2fb223a", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "\n", "names = np.array(\n", " [\n", " \"Liam\",\n", " \"Olivia\",\n", " \"Noah\",\n", " \"Liam\",\n", " \"Noah\",\n", " \"Olivia\",\n", " \"Liam\",\n", " \"Emma\",\n", " \"Oliver\",\n", " \"Ava\",\n", " ]\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "id": "f746e765", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['Ava', 'Emma', 'Liam', 'Noah', 'Oliver', 'Olivia'], dtype='