Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. import sys, json, numpy as np
  2.  
  3. #Read data from stdin
  4. def read_in():
  5. lines = sys.stdin.readlines()
  6. #Since our input would only be having one line, parse our JSON data from that
  7. return json.loads(lines[0])
  8.  
  9. def main():
  10. #get our data as an array from read_in()
  11. lines = read_in()
  12.  
  13. #create a numpy array
  14. np_lines = np.array(lines)
  15.  
  16. #use numpys sum method to find sum of all elements in the array
  17. lines_sum = np.sum(np_lines)
  18.  
  19. #return the sum to the output stream
  20. print lines_sum
  21.  
  22. #start process
  23. if __name__ == '__main__':
  24. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement