larray.Axis.by¶
-
Axis.
by
(self, length, step=None, template=None)[source]¶ Split axis into several groups of specified length.
Parameters: - length : int
length of groups
- step : int, optional
step between groups. Defaults to length.
- template : str, 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')