hw1_soln - #Solutions to HW01 by JRG from pylab import *...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#Solutions to HW01 by JRG from pylab import * import time def sumnums(*nums): sum=0 for num in nums: sum+=num return sum def myavg(*nums): sum=float(sumnums(*nums)) return sum/len(nums) def stddev(nums): ''' sigma=stddev(sequence) returns the standard deviation of the sequence of numbers ''' from math import sqrt N=len(nums) avgnum=myavg(*nums) sum=0. for num in nums: sum+=(num-avgnum)**2 return sqrt(sum/N) def randseq(mean,sd,number,type='g'): import random seq=[] if type=='g': for i in range(number): seq.append(random.gauss(mean,sd)) elif type=='u': for i in range(number): seq.append(random.uniform(mean,sd)) else: print "The type of distribution is 'g' for gaussian (default) or 'u' for uniform" return return seq def myhist(x,binsize,low=False,high=False): ''' bins,counts = myhist(sequence,binsize,low=lowcutoff,high=highcutoff) If 'low' and/or 'high' are not supplied, they default to the min and max of sequence. A tuple of arrays (bins and counts) are returned.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

hw1_soln - #Solutions to HW01 by JRG from pylab import *...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online