Skip to content

Center window and same length output  #19

Description

@matiasandina

I'm not sure whether this is in the documentation somewhere and I missed it, but I am trying to replicate the behavior of pandas rolling function:

.rolling(3, center=True, min_periods=0)

From the minimal example in the docs:

import numpy as np
import numpy_ext as npext

a = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
window = 3
npext.rolling_apply(np.sum, window, a, prepend_nans=True)
array([nan, nan,  3.,  6.,  9., 12., 15., 18., 21., 24.])
npext.rolling_apply(np.sum, window, a, prepend_nans=False)
array([ 3,  6,  9, 12, 15, 18, 21, 24])

Is there a way to get the result to match this pandas version?

pd.DataFrame(a).rolling(3, center=True, min_periods=0).apply(np.sum).values.flatten()
array([ 1.,  3.,  6.,  9., 12., 15., 18., 21., 24., 17.])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions