Advertisement
Guest User

kmeansReducer.py

a guest
Jun 18th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3.  
  4. currId = None
  5. currXs = []
  6. currYs = []
  7. id = None
  8.  
  9. for line in sys.stdin:
  10. line = line.strip()
  11. print line
  12. ln = line.split('\t')
  13. id = ln[0]
  14.  
  15. if str(currId) == str(id).replace(" ",""):
  16. currXs.append(int(ln[1]))
  17. currYs.append(int(ln[2]))
  18. else:
  19. if currId:
  20. centerX = sum(int(currXs))/len(currXs)
  21. centerY = sum(int(currYs))/len(currYs)
  22. print centerX," ",centerY
  23.  
  24. currId = id
  25. currXs.append(int(ln[1]))
  26. currYs.append(int(ln[2]))
  27.  
  28. if str(currId) == str(id).replace(" ",""):
  29. centerX = sum(currXs)/len(currXs)
  30. centerY = sum(currYs)/len(currYs)
  31. print centerX," ",centerY
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement