larray.LGroup.by
- LGroup.by(length, step=None, template=None) Tuple[Group]
Split group into several groups of specified length.
- Parameters
- lengthint
length of new groups
- stepint, optional
step between groups. Defaults to length.
- templatestr, optional
template describing how group names are generated. It is a string containing specific arguments written inside brackets {}. Available arguments are {start} and {end} representing the first and last label of each group. By default, template is defined as ‘{start}:{end}’.
- Returns
- list of Group
Notes
step can be smaller than length, in which case, this will produce overlapping groups.
Examples
>>> from larray import Axis, X >>> age = Axis('age=0..100') >>> young_children = age[0:6] >>> young_children.by(3) (age.i[0:3] >> '0:2', age.i[3:6] >> '3:5', age.i[6:7] >> '6') >>> young_children.by(3, step=2) (age.i[0:3] >> '0:2', age.i[2:5] >> '2:4', age.i[4:7] >> '4:6', age.i[6:7] >> '6') >>> young_children.by(3, template='{start}-{end}') (age.i[0:3] >> '0-2', age.i[3:6] >> '3-5', age.i[6:7] >> '6')