MCPcopy Index your code
hub / github.com/numpy/numpy / union1d

Function union1d

numpy/lib/_arraysetops_impl.py:1084–1113  ·  view source on GitHub ↗

Find the union of two arrays. 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 : ndarr

(ar1, ar2)

Source from the content-addressed store, hash-verified

1082
1083@array_function_dispatch(_union1d_dispatcher)
1084def union1d(ar1, ar2):
1085 """
1086 Find the union of two arrays.
1087
1088 Return the unique, sorted array of values that are in either of the two
1089 input arrays.
1090
1091 Parameters
1092 ----------
1093 ar1, ar2 : array_like
1094 Input arrays. They are flattened if they are not already 1D.
1095
1096 Returns
1097 -------
1098 union1d : ndarray
1099 Unique, sorted union of the input arrays.
1100
1101 Examples
1102 --------
1103 >>> import numpy as np
1104 >>> np.union1d([-1, 0, 1], [-2, 0, 2])
1105 array([-2, -1, 0, 1, 2])
1106
1107 To find the union of more than two arrays, use functools.reduce:
1108
1109 >>> from functools import reduce
1110 >>> reduce(np.union1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2]))
1111 array([1, 2, 3, 4, 6])
1112 """
1113 return unique(np.concatenate((ar1, ar2), axis=None))
1114
1115
1116def _setdiff1d_dispatcher(ar1, ar2, assume_unique=None):

Callers 2

test_union1dMethod · 0.90
test_manywaysMethod · 0.90

Calls 1

uniqueFunction · 0.70

Tested by 2

test_union1dMethod · 0.72
test_manywaysMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…