lookup
- arrayfire.lookup(array: Array, indices: Array, /, *, axis: int = 0) Array
Performs a lookup operation on the input ArrayFire array based on the specified indices along a given dimension.
This function gathers elements from the input array array at positions specified by the indices array. The operation is performed along the dimension specified by axis.
Parameters
- arrayArray
The input multi-dimensional ArrayFire array from which elements are to be gathered.
- indicesArray
An ArrayFire array containing the indices of elements to gather. The values in indices should be of integer type.
- axisint, optional, keyword-only, default: 0
The dimension along which the lookup is performed.
Returns
- Array
An ArrayFire array containing the elements of array at the locations specified by indices. The shape of the output array is determined by the shape of indices and the dimension specified by axis.
Examples
>>> import arrayfire as af >>> a = af.Array([1, 0, 3, 4, 5, 6], shape=(2, 3)) # Create a 2x3 array >>> a [2 3 1 1] 1.0000 3.0000 5.0000 0.0000 4.0000 6.0000
>>> idx = af.Array([0, 2]) # Indices for lookup >>> af.lookup(a, idx, axis=1) # Lookup along the second dimension [2 2 1 1] 1.0000 5.0000 0.0000 6.0000
>>> idx = af.Array([0]) # Indices for lookup >>> af.lookup(arr, idx, axis=0) # Lookup along the first dimension [1 3 1 1] 1.0000 3.0000 5.0000
Note
The indices array must contain integer values indicating the positions of elements to gather from array.
The dimension specified by axis must not exceed the number of dimensions in array.