0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

時系列データ解析でよく使うsliding windowをつくってみた。

Posted at

はじめに

配列を一定幅で切り出して分割する、いわゆるsliding windowは時系列データなどを扱うときに何かと便利です。ピリオドグラムウェルチのパワースペクトル短時間フーリエ変換などよく使われているのですが、see alsoに分割するときに用いる関数が載っていない。

ということで調べてそれっぽい引数で作ってみることにしました。といってもnumpy.lib.stride_tricks.sliding_window_viewを用いれば苦労なく完成ですね。つまりは備忘録です。

コード

from numpy.lib.stride_tricks import sliding_window_view

def divide_by_sliding_window(a, nperseg=256, noverlap=None):
    if noverlap == None:
        noverlap = nperseg // 2
    nstep = nperseg - noverlap
    return sliding_window_view(a, nperseg)[::nstep]

引数はscipyの関数に倣いました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?