get_item#

ivy.get_item(x, /, query, *, copy=None)[source]#

Gather slices from x according to query array, identical to x[query].

Parameters:
  • x (Union[Array, NativeArray]) – array, the array from which to gather values.

  • query (Union[Array, NativeArray, Tuple]) – array, index array, integer indices or boolean mask.

Return type:

Array

Returns:

ret – New array with the values gathered at the specified indices.

Functional Examples

>>> x = ivy.array([0, -1, 20])
>>> query = ivy.array([0, 1])
>>> print(ivy.get_item(x, query))
ivy.array([ 0, -1])
>>> x = ivy.array([[4, 5], [20, 128], [-2, -10]])
>>> query = ivy.array([[True, False], [False, False], [True, True]])
>>> print(ivy.get_item(x, query))
ivy.array([  4,  -2, -10])