-->

Thursday, September 27, 2012

python pills






# interpolating graph (to have a smooth effect) with spline

g11=[]
g11_p=[]
plot(range(0,len(g11_p)),signal.cspline1d(array(g11_p,dtype='float'),10.0),range(0,len(g)),signal.cspline1d(array(g,dtype='float'),10.0))

# parsing text between tokens

g=[]

for bl in re.findall('\\\\begin{BLOG}.*?\\\\end{BLOG}',open('2012_log.tex').read(),re.DOTALL):g.append(len(bl))


# reverse a list and stack it with zeros padding

g11.reverse()
g11_p=hstack((zeros(15),g11))

# parsing input files

lines=[f.strip().split() for f in open('test.lab').readlines()]

open= open the file 
readlines= read line by line 
strip= strip the \n 
split= split into multiple words (separated by spaces) 


# Load data from file
loadtxt('filename.txt') BUT ONLY if it contains numeric values
OR 
[line for line in open('filename.txt').readlines()]
OR 
f=list(np.fromfile('filename.txt'))


# Math stuff
from numpy import loadtxt,exp,ndarray import sys for i in 1/(1+exp(-loadtxt(sys.argv[1]))): print "%.2f" % pow(i*10,3)

No comments:

Post a Comment