Created
March 26, 2017 21:29
-
-
Save psudmant/45fd7c2b10bc4ea60710b207de0b970e to your computer and use it in GitHub Desktop.
flat convolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 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