{ "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": { "execution": { "iopub.execute_input": "2026-05-21T17:17:56.506623Z", "iopub.status.busy": "2026-05-21T17:17:56.506423Z", "iopub.status.idle": "2026-05-21T17:17:56.539613Z", "shell.execute_reply": "2026-05-21T17:17:56.539276Z", "shell.execute_reply.started": "2026-05-21T17:17:56.506604Z" } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "\n", "names = np.array(\n", " [\n", " \"Andrea\",\n", " \"Tim\",\n", " \"Veit\",\n", " \"Tim\",\n", " ],\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "id": "f746e765", "metadata": { "execution": { "iopub.execute_input": "2026-05-21T17:17:56.540120Z", "iopub.status.busy": "2026-05-21T17:17:56.539984Z", "iopub.status.idle": "2026-05-21T17:17:56.543533Z", "shell.execute_reply": "2026-05-21T17:17:56.543262Z", "shell.execute_reply.started": "2026-05-21T17:17:56.540106Z" } }, "outputs": [ { "data": { "text/plain": [ "array(['Andrea', 'Tim', 'Veit'], dtype='