# [SciPy-user] derivatives of datas?

manouchk manouchk at gmail.com
Wed Feb 8 16:05:02 CST 2006

```Thank you so much Nils!!!!!! I did adore!

Sorry for my probable exagerated enthusiasm, I just started to use python for
work a few days ago...

I'm just getting the position of the "smoothed" derivative of some datas. The
smoothing condition (s) though is critical!

peace of (bad, unoptimized etc...) code

allfiles=listdir(os.getcwd())
allfiles.sort()
for filename in allfiles:
if filename.find("plot"):
f = file(filename)
# get 7 column of float from file filename
data =
array([(float(x1),float(x2),float(x3),float(x4),float(x5),float(x6),float(x7))
for (x1,x2,x3,x4,x5,x6,x7) in [l.split() for l in f]])
#X=> col0
#Y=> (col1+col2+col3+col4+col5+col6)/5
X=data[:,0]
Y=(data[:,5]+data[:,4]+data[:,3]+data[:,2]+data[:,1])/5
#sX for smoothed_X have more ponts than data file
sX= arange(min(X),max(X),(max(X)-min(X))/1000)
#calculate B-spline representation
rep = scipy.interpolate.splrep(X, Y,s=1e-6)
#Evaulate a B-spline and its derivatives on sX
sY = scipy.interpolate.splev(sX, rep)
sDY = scipy.interpolate.splev(sX, rep, der=1)
sD2Y = scipy.interpolate.splev(sX, rep, der=2)
#look at the result
window(0)
plot(X,Y,'x',sX,sY,'o')
window(1)
plot (sX,sDY,'x')
window(2)
plot (sX,sD2Y,'x')
Ic=sX.tolist()[sDY.tolist().index(max(sDY))]

cheers,
EMmanuel

```