larray.LGroup.by

LGroup.by(length, step=None)

Split group into several groups of specified length.

Parameters:

length : int

length of new groups

step : int, optional

step between groups. Defaults to length.

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(range(10), 'age')
>>> age[[1, 2, 3, 4, 5]].by(2)
(age[1, 2], age[3, 4], age[5])
>>> age[1:5].by(2)
(age.i[1:3], age.i[3:5], age.i[5:6])
>>> age[1:5].by(2, 4)
(age.i[1:3], age.i[5:6])
>>> age[1:5].by(3, 2)
(age.i[1:4], age.i[3:6], age.i[5:6])
>>> X.age[[0, 1, 2, 3, 4]].by(2)
(X.age[0, 1], X.age[2, 3], X.age[4])