staircase.Stairs.slice#

Stairs.slice(cuts, closed: Literal['left', 'right', 'both', 'neither'] = 'left') staircase.core.slicing.StairsSlicer#

Slice the step function into pieces.

A slice corresponding to an interval (a,b) will be equal to self everywhere in (a,b) and undefined elsewhere.

Parameters
selfStairsclass
cuts

Used to slice the step function. If cuts is a sequence then it should comprised of monotonically increasing values from the step function domain.

closed{‘left’, ‘right’, ‘both’, ‘neither’}

Only relevant if cuts is not a `pandas.IntervalIndex`, and indicates if the intervals derived from cuts should closed on the left-side, right-side, both or neither.

Returns
`StairsSlicer`

Examples

```>>> s3.plot(arrows=True)
```
```>>> s3.slice(np.linspace(1,5,9))
```
```>>> s3.slice(np.linspace(1,5,9)).mean()
[1.0, 1.5)    1.0
[1.5, 2.0)    1.0
[2.0, 2.5)    0.0
[2.5, 3.0)    NaN
[3.0, 3.5)    NaN
[3.5, 4.0)    1.0
[4.0, 4.5)   -1.0
[4.5, 5.0)   -1.0
dtype: float64
```
```>>> s3.slice(np.linspace(0,6,4)).agg(["min", "max"])
min  max
[0.0, 2.0)  0.0  1.0
[2.0, 4.0)  0.0  1.0
[4.0, 6.0) -1.0  0.0
```
```>>> s3.slice(np.linspace(0,6,4)).hist(bins=[-1, -0.5, 0, 0.5, 1, 1.5])
[-1.0, -0.5)  [-0.5, 0.0)  [0.0, 0.5)  [0.5, 1.0)  [1.0, 1.5)
[0.0, 2.0)           0.0          0.0         1.0         0.0         1.0
[2.0, 4.0)           0.0          0.0         0.5         0.0         0.5
[4.0, 6.0)           1.0          0.0         1.0         0.0         0.0
```