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.

  • copy (Optional[bool], default: None) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy. In case copy is False we avoid copying by returning a view of the input array.

Return type:

Array

Returns:

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

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])