inplace_increment#

ivy.inplace_increment(x, val)[source]#

Perform in-place increment for the input array.

Parameters:
  • x (Union[Array, NativeArray]) – The input array to be incremented by the defined value.

  • val (Union[Array, NativeArray]) – The value of increment.

Return type:

Array

Returns:

ret – The array following the in-place increment.

Examples

With ivy.Array input:

>>> x = ivy.array([[5.3, 7., 0.],[6.8, 8, 3.9],[0., 10., 6.3]])
>>> y = ivy.inplace_increment(x, 3.)
>>> print(y)
ivy.array([[ 8.3, 10.,  3.],
   [ 9.8, 11.,  6.9],
   [ 3., 13.,  9.3]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.]))
>>> y = ivy.inplace_increment(x, 2.5)
>>> print(y)
{
    a: ivy.array([2.5, 17.5, 32.5]),
    b: ivy.array([2.5, 27.5, 52.5])
}
>>> x = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.]))
>>> y = ivy.Container(a=ivy.array([0., 15., 30.]), b=ivy.array([0., 25., 50.]))
>>> z = ivy.inplace_increment(x, y)
>>> print(z)
{
    a: ivy.array([0., 30., 60.]),
    b: ivy.array([0., 50., 100.])
}
Array.inplace_increment(self, val)[source]#

ivy.Array instance method variant of ivy.inplace_increment. This method wraps the function, and so the docstring for ivy.inplace_increment also applies to this method with minimal changes.

Parameters:
  • self (Array) – The input array to be incremented by the defined value.

  • val (Union[Array, NativeArray]) – The value of increment.

Return type:

Array

Returns:

ret – The array following an in-place increment.

Examples

With ivy.Array instance methods:

>>> x = ivy.array([5.7, 4.3, 2.5, 1.9])
>>> y = x.inplace_increment(1)
>>> print(y)
ivy.array([6.7, 5.3, 3.5, 2.9])
>>> x = ivy.asarray([4., 5., 6.])
>>> y = x.inplace_increment(2.5)
>>> print(y)
ivy.array([6.5, 7.5, 8.5])
Container.inplace_increment(self, val, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.inplace_increment. This method wraps the function, and so the docstring for ivy.inplace_increment also applies to this method with minimal changes.

Parameters:
  • self (Container) – Input container to apply an in-place increment.

  • val (Union[Array, NativeArray, Container]) – The value of increment.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

Return type:

Container

Returns:

ret – A container with the array following the in-place increment.

Examples

Using ivy.Container instance method: >>> x = ivy.Container(a=ivy.array([-6.7, 2.4, -8.5]), … b=ivy.array([1.5, -0.3, 0]), … c=ivy.array([-4.7, -5.4, 7.5])) >>> y = x.inplace_increment(2) >>> print(y) {

a: ivy.array([-4.7, 4.4, -6.5]), b: ivy.array([3.5, 1.7, 2.]), c: ivy.array([-2.7, -3.4, 9.5])

}