You are viewing a single comment's thread. Return to all comments →
def runningMedian(a): length = len(a) result = [] new_list = [] for i in range(0, length): insert(new_list, a[i]) if (i +1) % 2 == 0 and i>0: position = (i +1) // 2 median = (new_list[position] + new_list[position-1]) / 2 result.append(round(median, 1)) else: position = (i +1) // 2 median = (new_list[position]) result.append(round(median, 1)) return result def insert(arr, value): low = 0 high = len(arr) - 1 index = 0 while low <= high: mid = (low + high) // 2 if arr[mid] > value: index = mid high = mid - 1 else: index = mid +1 low = index
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Running Median
You are viewing a single comment's thread. Return to all comments →