Skip to content

Instantly share code, notes, and snippets.

@psudmant
Created March 26, 2017 21:29
Show Gist options
  • Select an option

  • Save psudmant/45fd7c2b10bc4ea60710b207de0b970e to your computer and use it in GitHub Desktop.

Select an option

Save psudmant/45fd7c2b10bc4ea60710b207de0b970e to your computer and use it in GitHub Desktop.
flat convolution
"""
flat convolution of width n on an array x in O(n) time
padded out to maintain shape
"""
def do_convolve(X, n):
csum = np.cumsum(X)
conv = np.r_[np.repeat(csum[n-1],n), csum[n:]-csum[:-n]]
return conv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment