Advertisement
furas

Python - numpy - mean,sum

May 28th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import numpy as np
  2.  
  3. data = np.array([ [40,60,3,3], [60,80,8,11], [80,100,30,41] ])
  4.  
  5. averages =  data[:,0:2].mean(axis=1)
  6. print('averages:', averages)
  7.  
  8. multiplications = averages * data[:,2]
  9. print('multiplications:', multiplications)
  10.  
  11. result = multiplications.sum()
  12. print('result:', result)
  13.  
  14. # the same in one line
  15.  
  16. result = (data[:,0:2].mean(axis=1)*data[:,2]).sum()
  17. print('result:', result)
  18.  
  19. '''
  20. averages: [ 50.  70.  90.]
  21. multiplications: [  150.   560.  2700.]
  22. result: 3410.0
  23. result: 3410.0
  24. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement