def sliding_window_1D(x, windowLen):
"""
Constructs a 2D array whose rows are the data in a sliding window that
advances one time step at a time.
Parameters
----------
x : 1D, array-like
An ordered collection of objects
windowLen : int > 0
The legnth of the sliding window
Returns
-------
X : 2D array
A matrix such that X[i, :] = x[i:i+windowLen]
"""
x = x.flatten()
numBytes = x.strides[0]
numSubseqs = len(x) - windowLen + 1
return as_strided(x, strides=(numBytes, numBytes), shape=(numSubseqs, windowLen))
评论列表
文章目录