lerp#

ivy.lerp(input, end, weight, /, *, out=None)[source]#

Return a linear interpolation of two arrays start (given by input) and end.

based on a scalar or array weight.

input + weight * (end - input), element-wise.

Parameters:
  • input (Union[Array, NativeArray]) – array of starting points

  • end (Union[Array, NativeArray]) – array of ending points

  • weight (Union[Array, NativeArray, float]) – the weight for the interpolation formula. Scalar or Array.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – The result of input + ((end - input) * weight)

Examples

With ivy.Array inputs: >>> input = ivy.array([1, 2, 3]) >>> end = ivy.array([10, 10, 10]) >>> weight = 0.5 >>> y = ivy.lerp(input, end, weight) >>> print(y) ivy.array([5.5, 6. , 6.5])

>>> input = ivy.array([1.1, 1.2, 1.3])
>>> end = ivy.array([20])
>>> weight = ivy.array([0.4, 0.5, 0.6])
>>> y = ivy.zeros(3)
>>> ivy.lerp(input, end, weight, out=y)
>>> print(y)
ivy.array([ 8.65999985, 10.60000038, 12.52000046])
>>> input = ivy.array([[4, 5, 6],[4.1, 4.2, 4.3]])
>>> end = ivy.array([10])
>>> weight = ivy.array([0.5])
>>> ivy.lerp(input, end, weight, out=input)
>>> print(input)
ivy.array([[7.        , 7.5       , 8.        ],
       [7.05000019, 7.0999999 , 7.1500001 ]])

With ivy.Container input: >>> input = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.])) >>> end = ivy.array([10.]) >>> weight = 1.1 >>> y = input.lerp(end, weight) >>> print(y) {

a: ivy.array([11., 10.90000057, 10.80000019]), b: ivy.array([10.70000076, 10.60000038, 10.5])

}

>>> input = ivy.Container(a=ivy.array([10.1, 11.1]), b=ivy.array([10, 11]))
>>> end = ivy.Container(a=ivy.array([5]), b=ivy.array([0]))
>>> weight = 0.5
>>> y = input.lerp(end, weight)
>>> print(y)
{
    a: ivy.array([7.55000019, 8.05000019]),
    b: ivy.array([5., 5.5])
}
Array.lerp(self, end, weight, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – Array of starting points

  • end (Array) – Array of ending points

  • weight (Union[Array, float]) – Weight for the interpolation formula , array or scalar.

  • out (Optional[Array], default: None) – Alternate output array in which to place the result. The default is None.

Return type:

Array

Returns:

ret – The linear interpolation between array self and array end based on scalar or array weight self + ((end - self) * weight)

Examples

>>> x = ivy.array([1.0, 2.0, 3.0, 4.0])
>>> end = ivy.array([10.0, 10.0, 10.0, 10.0])
>>> weight = 0.5
>>> x.lerp(end, weight)
ivy.array([5.5, 6. , 6.5, 7. ])
Container.lerp(self, end, weight, /, *, out=None)[source]#

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

Parameters:
  • self (Container) – The container whose arrays should be used as parameter: input

  • end (Union[Array, NativeArray, Container]) – The container whose arrays should be used as parameter: end

  • weight (Union[Array, NativeArray, float, Container]) – The container whose arrays or scalar should be used as parameter: weight

  • out (Optional[Container], default: None) – optional output container, for writing the result to.

Return type:

Container

Returns:

ret – container including input + ((end - input) * weight)

Examples

With one ivy.Container input: >>> input = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([1, 5, 10])) >>> end = ivy.Container(a=ivy.array([10, 10, 10]), b=ivy.array([20, 20, 20])) >>> weight = ivy.Container(a=ivy.array(0.5), b=ivy.array([0.4, 0.5, 0.6])) >>> input.lerp(end, weight) {

a: ivy.array([5.5, 6., 6.5]), b: ivy.array([8.60000038, 12.5, 16.])

}