Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # test input
  2. _x = [1,1,4,8,9,5]
  3. _mu = 3
  4.  
  5. # define function to handle CUSUM
  6. def add_by_one(input_array, my_mu):
  7.  
  8.   # initialize new array that we will return with cumulative sum values
  9.   new_array = []
  10.  
  11.   # S0 = 0 by definition
  12.   new_array.append(0)
  13.  
  14.   # loop through the input array values, arrays start at 0
  15.  
  16.   for index in range(len(input_array) - 1):
  17.     current_sum = new_array[index] + input_array[index] - my_mu
  18.     current_value = max(0, current_sum)
  19.     new_array.append(current_value)
  20.  
  21.   return new_array
  22.  
  23. print(add_by_one(_x, _mu))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement