Module window
source code
window PREDICATE
window -o WINDOW_SIZE
window -d WINDOW_SIZE
Groups of consecutive input objects are formed into tuples which are
passed to the output stream. The objects are grouped in one of two
mechanisms.
1) A new group is started on the first input object, and for any
subsequent object for which PREDICATE
returns true. For
example, if the input stream contains the integers 1, 2, 3,
...
, then:
window 'n: n % 3 == 2'
yields as output:
((1,),)
((2,), (3,), (4,))
((5,), (6,), (7,))
((8,), (9,), (10,))
...
I.e., a new tuple is started for each integer n such that n % 3 =
2.
2) Groups have a fixed number of objects. The -o
and
-d
flags specify WINDOW_SIZE
, the number of
objects in the groups. -o
specifies overlapping
windows, in which each input object begins a new list containing
WINDOW_SIZE
items. Groups may be padded with
None
values to ensure that the group's size is
WINDOW_SIZE
.
Example: For input 0, 1, ..., 9
, window -o
3
yields these tuples:
((0,), (1,), (2,))
((1,), (2,), (3,))
((2,), (3,), (4,))
((3,), (4,), (5,))
((4,), (5,), (6,))
((5,), (6,), (7,))
((6,), (7,), (8,))
((7,), (8,), (9,))
((8,), (9,), (None,))
((9,), (None,), (None,))
-d
specifies disjoint windows, in which each input
object appears in only one group. A new group is started every
WINDOW_SIZE
objects. The last window may be padded with
(None,) to ensure that it has WINDOW_SIZE
elements.
Example: For input 0, 1, ..., 9
, window -d
3
yields these tuples:
((0,), (1,), (2,))
((3,), (4,), (5,))
((6,), (7,), (8,))
((9,), (None,), (None,))
|
window(predicate=None,
disjoint=None,
overlap=None)
Groups of consecutive input objects are formed into tuples which
are passed to the output stream. |
source code
|
|
window(predicate=None,
disjoint=None,
overlap=None)
| source code
|
Groups of consecutive input objects are formed into tuples which are
passed to the output stream. Only one of predicate ,
disjoint , ant overlap may be specified. If
predicate , a function returning a boolean, is specified,
then a new group of objects is started for the first input, and
subsequently for every input object which causes predicate
to return true. If disjoint , an integer, is specified, then
the input is broken into disjoint groups of disjoint objects
each. If overlap , an int, is specified, then each input
object begins a group of overlap objects. For both
disjoint and overlap , groups may be padded with
None values to form groups of the required size.
|