Which one is better and when
I was coding (a) part of ex1 of Exercise sheet 1.
There is a simple pythonic way to calculate F(x):
x = np.log(np.sort(numbers)) y = np.log(np.arange(len(numbers),0,-1) / len(numbers)) pylab.plot(x,y) pylab.show()
However this should not work when we have equal x values. (Right?) Therefore I made the following more non-pythonic solution
y= x= numbers.sort() for i in range(1,len(numbers)): if(numbers[i]!=numbers[i-1]): x.append(numbers[i]) y.append(float((len(numbers)-i))/len(numbers)) x=np.log(x); y=np.log(y); pylab.plot(x,y) pylab.show()
Which one is better? Do we have to worry for equal values in general or it's more like task-dependent?
empDistX =  empDistY =  numbers = sorted(data) #sorted() is more pythonic, and is valid over all iterables for i, x in enumerate(numbers): #get the element and index in 1 go if(x not in empDistX): #this incurs a slight performance hit #but is more in the python style empDistX.append(x) empDistY.append(float(length - i)/ length)
I believe we do have to worry about equal values - in general and in this specific case.
Alright, that's part 1a done... part 1b!