Defined in tensorflow/contrib/data/python/ops/

A sliding window with size of window_size and step of stride.

This transformation passes a sliding window over this dataset. The window size is window_size and step size is stride. If the left elements cannot fill up the sliding window, this transformation will drop the final smaller element. For example:

# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { [1], [2], [3], [4], [5], [6] }

a.apply(, stride=2)) ==
    [[1], [2], [3]],
    [[3], [4], [5]],


  • window_size: A tf.int64 scalar tf.Tensor, representing the number of elements in the sliding window.
  • stride: (Optional.) A tf.int64 scalar tf.Tensor, representing the steps moving the sliding window forward for one iteration. The default is 1. It must be in [1, window_size).


A Dataset transformation function, which can be passed to