x.sort() just sorts the array but does not return the sorted array. Fix: First sorting the array, then returning the sorted array
list.append() changes the original list. Fixed by using 'deepcopy' of the original list
trapz(x, y) does not work, it  needs to be trapz(y, x=x)
y[i] = .. changes y, the original array, too. Fixed by creating a new array consisting of zeros with the shape of y, so that y is not changed
changed png file