put_along_axis#

ivy.put_along_axis(arr, indices, values, axis, /, *, mode='replace', out=None)[source]#

Put values into the input array by matching 1d index and data slices along a specified axis.

Parameters:
  • arr (array_like) – The input array to modify.

  • indices (array_like) – The indices of the values to put into arr.

  • values (array_like) – The values to put into arr.

  • axis (int) – The axis over which to put the values.

  • mode ({'sum', 'min', 'max', 'mul', 'replace'}) – The reduction operation to apply.

  • out (ndarray, optional) – Output array in which to place the result. If not specified, a new array is created.

Note

In case indices contains duplicates, the updates get accumulated in each place.

Return type:

None

Returns:

None

Examples

>>> arr = ivy.array([[4, 3, 5], [1, 2, 1]])
>>> indices = ivy.array([[0, 1, 1], [2, 0, 0]])
>>> values = ivy.array([[9, 8, 7], [6, 5, 4]])
>>> ivy.put_along_axis(arr, indices, values, 1, mode='replace')
>>> print(arr)
ivy.array([[9, 7, 5],
           [4, 2, 6]])
>>> arr = ivy.array([[10, 30, 20], [60, 40, 50]])
>>> axis = 1
>>> indices = ivy.argmax(arr, axis=axis, keepdims=True)
>>> value = 100
>>> ivy.put_along_axis(arr, indices, value, axis, mode='sum')
>>> print(arr)
ivy.array([[10, 30, 20],
          [60, 40, 50]])
Array.put_along_axis(self, indices, values, axis, /, *, mode='replace', out=None)[source]#

ivy.Array instance method variant of ivy.put_along_axis.

This method simply wraps the function, and so the docstring for ivy.put_along_axis also applies to this method with minimal changes.

Return type:

Array

Container.put_along_axis(self, indices, values, axis, /, *, mode='replace', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.put_along_axis.

This method simply wraps the function, and so the docstring for ivy.put_along_axis also applies to this method with minimal changes.

Return type:

Container