set_item#

ivy.set_item(x, query, val, /, *, copy=False)[source]#

Replace slices of x (defined by query) with val, identical to x[query] = val.

Parameters:
  • x (Union[Array, NativeArray]) – the array to be updated.

  • query (Union[Array, NativeArray, Tuple]) – either an index array, or a tuple of integers or slices.

  • val (Union[Array, NativeArray]) – the array containing the values to be infused into x

  • copy (Optional[bool], default: False) – boolean indicating whether to copy x. If True, the function will update and return a copy of x. If False, the function will update x inplace.

Return type:

Array

Returns:

ret – the array with updated values at the specified indices.

Examples

>>> x = ivy.array([0, -1, 20])
>>> query = ivy.array([0, 1])
>>> val = ivy.array([10, 10])
>>> ivy.set_item(x, query, val)
>>> print(x)
ivy.array([10, 10, 20])
>>> x = ivy.array([[0, -1, 20], [5, 2, -8]])
>>> query = ivy.array([1, 1])
>>> val = ivy.array([10, 10])
>>> y = ivy.set_item(x, query, val, copy=True)
>>> print(y)
ivy.array([[ 0, -1, 20],
       [10, 10, 10]])