larray.Axis.by

Axis.by(length, step=None, template=None) Tuple[Group, ...][source]

Split axis into several groups of specified length.

Parameters
lengthint

length of 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

>>> age = Axis('age=0..6')
>>> age
Axis([0, 1, 2, 3, 4, 5, 6], 'age')
>>> age.by(3)
(age.i[0:3] >> '0:2', age.i[3:6] >> '3:5', age.i[6:7] >> '6')
>>> age.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')
>>> age.by(3, template='{start}-{end}')
(age.i[0:3] >> '0-2', age.i[3:6] >> '3-5', age.i[6:7] >> '6')