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)
| 1082 | |
| 1083 | @array_function_dispatch(_union1d_dispatcher) |
| 1084 | def 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 | |
| 1116 | def _setdiff1d_dispatcher(ar1, ar2, assume_unique=None): |
searching dependent graphs…