Skip to content

Instantly share code, notes, and snippets.

@bmcfee
Created August 15, 2019 22:00
Show Gist options
  • Save bmcfee/9f079cd2f70da801d62d7e8213c50e41 to your computer and use it in GitHub Desktop.
Save bmcfee/9f079cd2f70da801d62d7e8213c50e41 to your computer and use it in GitHub Desktop.
In-place patching (framing of 2d inputs)
def frame2d(x, patch_length, hop_length):
n_frames = 1 + (x.shape[-1] - patch_length) // hop_length
x_frame = np.lib.stride_tricks.as_strided(x, shape=(x.shape[0], patch_length, n_frames),
strides=(1 * x.itemsize, x.shape[0] * x.itemsize, hop_length * x.shape[0] * x.itemsize))
return x_frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment