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

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 0.50 KB  |  hits: 15  |  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. Normalizing periodic data in Python
  2. (1, 23), (2, 42), (3.5, 89), (5, 73), (7, 54), (8, 41), (8.5, 37), (9, 23)
  3.        
  4. import numpy as np
  5.  
  6. a = np.array([(1, 23), (2, 42), (3.5, 89), (5, 73), (7, 54), (8, 41), (8.5, 37), (9, 23)])
  7.  
  8. x = np.arange(1, 10) # target x values
  9.  
  10. b = zip(x, np.interp(x, a[:,0], a[:,1]))
  11.  
  12. # b == [(1, 23.0),
  13. #       (2, 42.0),
  14. #       (3, 73.333333333333329),
  15. #       (4, 83.666666666666671),
  16. #       (5, 73.0),
  17. #       (6, 63.5),
  18. #       (7, 54.0),
  19. #       (8, 41.0),
  20. #       (9, 23.0)]