This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / union1d

_ArrayFunctionDispatcher

numpy:union1d

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_arraysetops_impl.py :1083

Signature

def   union1d ( ar1 ar2 )

Summary

Find the union of two arrays.

Extended Summary

Return the unique, sorted array of values that are in either of the two input arrays.

Parameters

ar1, ar2 : array_like

Input arrays. They are flattened if they are not already 1D.

Returns

union1d : ndarray

Unique, sorted union of the input arrays.

Examples

import numpy as np
np.union1d([-1, 0, 1], [-2, 0, 2])
To find the union of more than two arrays, use functools.reduce:
from functools import reduce
reduce(np.union1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2]))

Aliases

  • numpy.union1d