window for filters
Creates a sliding window of `window_size` that slide by n rows/elements across input.
Signature
> window {flags} (window_size)
Flags
-
--stride, -s {int}: The number of rows to slide over between windows. -
--remainder, -r: Yield last chunks even if they have fewer elements than size.
Parameters
-
window_size: The size of each window.
Input/output types:
| input | output |
|---|---|
| list<any> | list<list<any>> |
Examples
A sliding window of two elements.
> [1 2 3 4] | window 2 ╭───┬───────────╮ │ 0 │ ╭───┬───╮ │ │ │ │ 0 │ 1 │ │ │ │ │ 1 │ 2 │ │ │ │ ╰───┴───╯ │ │ 1 │ ╭───┬───╮ │ │ │ │ 0 │ 2 │ │ │ │ │ 1 │ 3 │ │ │ │ ╰───┴───╯ │ │ 2 │ ╭───┬───╮ │ │ │ │ 0 │ 3 │ │ │ │ │ 1 │ 4 │ │ │ │ ╰───┴───╯ │ ╰───┴───────────╯
A sliding window of two elements, with a stride of 3.
> [1, 2, 3, 4, 5, 6, 7, 8] | window 2 --stride 3 ╭───┬───────────╮ │ 0 │ ╭───┬───╮ │ │ │ │ 0 │ 1 │ │ │ │ │ 1 │ 2 │ │ │ │ ╰───┴───╯ │ │ 1 │ ╭───┬───╮ │ │ │ │ 0 │ 4 │ │ │ │ │ 1 │ 5 │ │ │ │ ╰───┴───╯ │ │ 2 │ ╭───┬───╮ │ │ │ │ 0 │ 7 │ │ │ │ │ 1 │ 8 │ │ │ │ ╰───┴───╯ │ ╰───┴───────────╯
A sliding window of equal stride that includes remainder. Equivalent to chunking.
> [1, 2, 3, 4, 5] | window 3 --stride 3 --remainder ╭───┬───────────╮ │ 0 │ ╭───┬───╮ │ │ │ │ 0 │ 1 │ │ │ │ │ 1 │ 2 │ │ │ │ │ 2 │ 3 │ │ │ │ ╰───┴───╯ │ │ 1 │ ╭───┬───╮ │ │ │ │ 0 │ 4 │ │ │ │ │ 1 │ 5 │ │ │ │ ╰───┴───╯ │ ╰───┴───────────╯
Notes
This command will error if window_size or stride are negative or zero.
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/window.html