Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import pprint
  2. import numpy as np
  3.  
  4. def correlation(x, y, t):
  5.     q = len(x)
  6.     c = 0
  7.     h = []
  8.     soma = []
  9.     for j in xrange(q):
  10.         if x[j] == y[(j + t)%q]:
  11.             c += 1
  12.             h.append([1])
  13.         else:
  14.             h.append([0])
  15.     soma.append([c])
  16.     return t, h, c, "outro tal"
  17.     print soma.append([c])
  18.    
  19. def correlation_h(x, y):
  20.     ns1 = len(x)
  21.     ns2 = len(y)
  22.     return [correlation(x, y, i) for i in xrange(-ns2/2, ns1/2 + 1)]
  23.  
  24.  
  25.  
  26. x = [1, 4, 5, 5, 2, 7, 3, 5, 8, 3, 2, 4, 2, 1, 7, 6, 6, 0, 4, 8, 6, 3, 8, 0, 7, 0]
  27.  
  28. y = [[1, 4, 5, 5, 2, 7, 3, 5, 8, 3, 2, 4, 2, 1, 7, 6, 6, 0, 4, 8, 6, 3, 8, 0, 7, 0],
  29.      [25, 4, 18, 10],
  30.      [26, 5, 19, 11],
  31.      [23, 2, 16, 8] ]
  32.  
  33.  
  34. print (correlation_h(x, y[0]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement