Skip to main content

Create a rolling window from a 1-D numpy ndarray

Project description

get-rolling-window

Gets an array of size-period rolling windows from an numpy 1-D array

Install

$ pip install get-rolling-window

Usage

import numpy as np
from get_rolling_window import rolling_window

array = np.arange(1, 8)

rolling_window(array, 3, 2)
# array([[1, 2, 3],
#        [3, 4, 5],
#        [5, 6, 7]])

rolling_window(array, size, shift, stride) -> np.ndarray

|-------- size:3 --------|
|- stride:1 -|           |
|            |           |
1            2           3 --------|---
                                shift:2
3            4           5 --------|---

5            6           7
  • array np.ndarray The 1-D numpy array. If the given array has more than one dimensions, it will be treated as a 1-D array.
  • size int The size of the window.
  • shift? int=None The shift argument determines the number of input elements by which the window moves on each iteration. Defaults to size.
  • stride? int=1 Determines the stride of the input elements. Defaults to 1.

Returns np.ndarray

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get-rolling-window-1.0.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

get_rolling_window-1.0.0-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page