MCPcopy Create free account
hub / github.com/numpy/numpy / union1d

Function union1d

numpy/lib/arraysetops.py:899–932  ·  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

897
898@array_function_dispatch(_union1d_dispatcher)
899def union1d(ar1, ar2):
900 """
901 Find the union of two arrays.
902
903 Return the unique, sorted array of values that are in either of the two
904 input arrays.
905
906 Parameters
907 ----------
908 ar1, ar2 : array_like
909 Input arrays. They are flattened if they are not already 1D.
910
911 Returns
912 -------
913 union1d : ndarray
914 Unique, sorted union of the input arrays.
915
916 See Also
917 --------
918 numpy.lib.arraysetops : Module with a number of other functions for
919 performing set operations on arrays.
920
921 Examples
922 --------
923 >>> np.union1d([-1, 0, 1], [-2, 0, 2])
924 array([-2, -1, 0, 1, 2])
925
926 To find the union of more than two arrays, use functools.reduce:
927
928 >>> from functools import reduce
929 >>> reduce(np.union1d, ([1, 3, 4, 3], [3, 1, 2, 1], [6, 3, 4, 2]))
930 array([1, 2, 3, 4, 6])
931 """
932 return unique(np.concatenate((ar1, ar2), axis=None))
933
934
935def _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