Index an array using another array. More...

Functions

AFAPI array lookup (const array &in, const array &idx, const int dim=-1)
 Lookup the values of input array based on index. More...
 
AFAPI af_err af_lookup (af_array *out, const af_array in, const af_array indices, const unsigned dim)
 Lookup the values of input array based on index. More...
 

Detailed Description

Index an array using another array.

Lets look at an example of how af::lookup function does indexing.

array a = range(dim4(5));
// 0
// 1
// 2
// 3
// 4
array b = range(dim4(2)) + 2; // Create an array with values [0,2] range and add 2 to them
// 2
// 3
array c = lookup(a, b, 0);
// 2
// 3
array d = lookup(a, b, 1);
// 0 0
// 1 1
// 2 2
// 3 3
// 4 4
// Since the second(1) dimension has only single element, all indices map to first & single element
// along that dimension. Thus, the output array has two columns with elements repeatd twice because
// the index array b has 2 elements.

Function Documentation

◆ af_lookup()

AFAPI af_err af_lookup ( af_array out,
const af_array  in,
const af_array  indices,
const unsigned  dim 
)

Lookup the values of input array based on index.

Parameters
[out]outoutput array containing values at locations specified by index
[in]inis input lookup array
[in]indicesis lookup indices
[in]dimspecifies the dimension for indexing

◆ lookup()

AFAPI array af::lookup ( const array in,
const array idx,
const int  dim = -1 
)

Lookup the values of input array based on index.

Parameters
[in]inis input lookup array
[in]idxis lookup indices
[in]dimspecifies the dimension for indexing
Returns
an array containing values at locations specified by index
Examples:
machine_learning/bagging.cpp, and machine_learning/naive_bayes.cpp.