set_union

arrayfire.set_union(x: Array, y: Array, /, *, is_unique: bool = False) Array

Computes the union of two 1D ArrayFire arrays, effectively combining the elements from both arrays and removing duplicates.

Parameters

x, yArray

The input 1D ArrayFire arrays whose union is to be computed. These arrays can contain any numerical type.

is_uniquebool, optional, keyword-only, default: False

A flag that indicates whether both input arrays are guaranteed to contain unique elements. Setting this to True can optimize the computation but should only be used if each element in both arrays is indeed unique.

Returns

Array

An ArrayFire array containing the unique elements from both x and y.

Examples

>>> import arrayfire as af
>>> a = af.Array([1, 2, 3, 4, 5])
>>> b = af.Array([4, 5, 6, 7, 8])
>>> af.set_union(a, b)
[8 1 1 1]
    1.0000
    2.0000
    3.0000
    4.0000
    5.0000
    6.0000
    7.0000
    8.0000

Note

The operation is performed on 1D arrays. For inputs that are not 1D, consider reshaping or flattening them before performing the operation to ensure correct results. The is_unique flag should be used with caution; incorrect usage (i.e., setting it to True when arrays are not composed of unique elements) may lead to unexpected results.