reduce_window#

ivy.reduce_window(operand, init_value, computation, window_dimensions, /, *, window_strides=1, padding='VALID', base_dilation=1, window_dilation=1)[source]#

Apply a reduction function to all elements in each window of an array.

Parameters:
  • operand (Union[Array, NativeArray]) – An array representing the base area on which the window is going to slide over.

  • init_value (Union[int, float]) – The starting value for the reduction.

  • computation (Callable) – The reduction function to apply to elements in each window.

  • window_dimensions (Union[int, Sequence[int]]) – A sequence containing the window dimensions.

  • window_strides (Union[int, Sequence[int]], default: 1) – A sequence containing the window strides.

  • padding (Union[str, int, Sequence[Tuple[int, int]]], default: 'VALID') – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • base_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the base dilation values.

  • window_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the window dilation values.

Return type:

Array

Returns:

ret – The result of the pooling-like operation.

Examples

>>> x = ivy.array([[1, 2, 3, 4],
>>>                [5, 6, 7, 8],
>>>                [9, 10, 11, 12]])
>>> ivy.reduce_window(x, 0, ivy.add, (2, 2))
ivy.array([[14, 18, 22], [30, 34, 38]])
Array.reduce_window(self, init_value, computation, window_dimensions, /, *, window_strides=1, padding='VALID', base_dilation=1, window_dilation=1)[source]#

Apply a reduction function to all elements in each window of an array.

Parameters:
  • self (Array) – An array representing the base area on which the window is going to slide over.

  • init_value (Union[int, float]) – The starting value for the reduction.

  • computation (Callable) – The reduction function to apply to elements in each window.

  • window_dimensions (Union[int, Sequence[int]]) – A sequence containing the window dimensions.

  • window_strides (Union[int, Sequence[int]], default: 1) – A sequence containing the window strides.

  • padding (Union[str, int, Sequence[Tuple[int, int]]], default: 'VALID') – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • base_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the base dilation values.

  • window_dilation (Union[int, Sequence[int]], default: 1) – A sequence containing the window dilation values.

Return type:

Array

Returns:

ret – The result of the pooling-like operation.

Examples

>>> x = ivy.array([[1, 2, 3, 4],
>>>                [5, 6, 7, 8],
>>>                [9, 10, 11, 12]])
>>> x.reduce_window(0, ivy.sum, (2, 2))
ivy.array([[32.]])
Container.reduce_window(self, init_value, computation, window_dimensions, /, *, window_strides=1, padding='VALID', base_dilation=1, window_dilation=1, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

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

Parameters:
  • self (Container) – A container representing the base areas on which the window is going to slide over.

  • init_value (Union[int, float, Container]) – The starting value for the reduction.

  • computation (Union[Callable, Container]) – The reduction function to apply to elements in each window.

  • window_dimensions (Union[int, Sequence[int], Container]) – A sequence containing the window dimensions.

  • window_strides (Union[int, Sequence[int], Container], default: 1) – A sequence containing the window strides.

  • padding (Union[str, int, Sequence[Tuple[int, int]], Container], default: 'VALID') – Either the string ‘SAME’ (padding with zeros evenly), the string ‘VALID’ (no padding), or a sequence of n (low, high) integer pairs that give the padding to apply before and after each spatial dimension.

  • base_dilation (Union[int, Sequence[int], Container], default: 1) – A sequence containing the base dilation values.

  • window_dilation (Union[int, Sequence[int], Container], default: 1) – A sequence containing the window dilation values.

Return type:

Container

Returns:

ret – The result of the pooling-like operation.

Examples

>>> x = ivy.Container(
...     a=ivy.array([[1, 2, 3, 4],
...                  [5, 6, 7, 8],
...                  [9, 10, 11, 12]]),
...     b=ivy.array([[13, 14, 15, 16],
...                  [17, 18, 19, 20],
...                  [21, 22, 23, 24]])
... )
>>> x.reduce_window(0, ivy.sum, (2, 2))
{
    a: ivy.array([[21 25 29]
                  [33 37 41]
                  [45 49 53]]),
    b: ivy.array([[63 67 71]
                  [75 79 83]
                  [87 91 95]])
}