Guest User

Untitled

a guest
Feb 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. def calculateHistogram(nbins,data):
  2.     step = 1/float(nbins)
  3.     hist = [0 for i in range(0,nbins)]
  4.  
  5.     for sample in data:
  6.         for i in range(0,nbins):
  7.             left = i*step
  8.             right = (i+1)*step
  9.             if i == nbins-1:
  10.                 if sample >= left and sample <= right:
  11.                     hist[i] = hist[i]+1
  12.             else:
  13.                 if sample >= left and sample < right:
  14.                     hist[i] = hist[i]+1
  15.     for i in range(0,len(hist)):
  16.         hist[i] = hist[i] / float(len(data))
  17.     return hist
  18.        
  19.  
  20. def calculateSTA2(wormPatches,nbins2):
  21.     out = open("d:\out.txt","w")
  22.     rows = len(wormPatches)
  23.     cols = len(wormPatches[0])
  24.     sta2 = [[] for i in range(0,rows)]
  25.     for j in range(0,cols):
  26.         data = []
  27.         for i in range(0,rows):
  28.             data.append(wormPatches[i][j])
  29.             hist = calculateHistogram(nbins2,data)
  30.             sta2[i].extend(hist)
  31.        
  32.     for l in sta2:
  33.         line = ""
  34.         for e in l:
  35.             line = line + ", " + str(e)
  36.         line = line + "\n"
  37.         out.write(line)
  38.     out.flush()
  39.     out.close()
Add Comment
Please, Sign In to add comment