x has no function sort(). use np.sort(x) instead
value and new_value were pointing at the same list in memory. use deepcopy() to assign new_value to a copy of the list. also used np.abs() to calulate the absolute value of the difference
trapz takes arguments in another order
while median-filtering, the array y was changed. to avoid this fill a new array with the filtered values