Skip to content

Commit

Permalink
Add missing example file
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Dec 31, 2014
1 parent da21a6e commit 9168807
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/movemean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
A moving average function using @guvectorize.
"""

import numpy as np

from numba import guvectorize

@guvectorize(['void(float64[:], intp[:], float64[:])'], '(n),()->(n)')
def move_mean(a, window_arr, out):
window_width = window_arr[0]
asum = 0.0
count = 0
for i in range(window_width):
asum += a[i]
count += 1
out[i] = asum / count
for i in range(window_width, len(a)):
asum += a[i] - a[i - window_width]
out[i] = asum / count

arr = np.arange(20, dtype=np.float64).reshape(2, 10)
print(arr)
print(move_mean(arr, 3))

0 comments on commit 9168807

Please sign in to comment.