多行数据滑窗法数据增强python代码
时间: 2023-09-17 12:15:04 浏览: 140
以下是多行数据滑窗法数据增强的Python代码:
```python
def sliding_window(data, window_size, stride):
'''
data: input data, shape (n_samples, n_features)
window_size: size of the sliding window
stride: stride of the sliding window
'''
n_samples, n_features = data.shape
n_windows = (n_samples - window_size) // stride + 1
windows = np.zeros((n_windows, window_size, n_features))
for i in range(n_windows):
windows[i] = data[i*stride:i*stride+window_size]
return windows
```
其中,`data`为输入数据,形状为`(n_samples, n_features)`;`window_size`为滑动窗口的大小;`stride`为滑动窗口的步长。函数返回的是滑动窗口的数据,形状为`(n_windows, window_size, n_features)`,其中`n_windows`为滑动窗口的数量。
阅读全文