Don't like ads? PRO users don't see any ads ;-)
Guest

sum_rand

By: a guest on Jun 6th, 2011  |  syntax: Python  |  size: 0.56 KB  |  hits: 108  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import numpy as N
  2.  
  3. def genrand(num):
  4.         return N.ones(num)/num
  5.  
  6. def combine(rand1, rand2):
  7.         output = N.zeros(len(rand1)-1 + len(rand2))
  8.         for i in range(len(output)):
  9.                 first = i
  10.                 second = 0
  11.                 while first >= 0:
  12.                         if first < len(rand1) and second < len(rand2):
  13.                                 output[i] += rand1[first]*rand2[second]
  14.                         first -= 1
  15.                         second += 1
  16.         return output
  17.        
  18. r1 = genrand(100)
  19. r2 = genrand(101)
  20. r3 = genrand(101)
  21. randsum = combine(r1, combine(r2, r3))
  22. final = N.zeros(100)
  23. for i in range(len(final)):
  24.         final[i] = randsum[3*i] + randsum[3*i + 1] + randsum[3*i + 2]