comparison tests/test_broadcasting.py @ 15:926c127305fa

[np] this is how broadcasting works
author Jeff Hammel <k0scist@gmail.com>
date Sun, 03 Sep 2017 12:11:03 -0700
parents ec5f97abf8ed
children
comparison
equal deleted inserted replaced
14:ec5f97abf8ed 15:926c127305fa
13 [1.2, 104., 52., 8.], # protein 13 [1.2, 104., 52., 8.], # protein
14 [1.8, 135., 99., 0.9]] # fat 14 [1.8, 135., 99., 0.9]] # fat
15 15
16 class TestBroadcasting(unittest.TestCase): 16 class TestBroadcasting(unittest.TestCase):
17 def test_basic(self): 17 def test_basic(self):
18 """example of braodcasting""" 18 """example of broadcasting"""
19
20 A = np.array(calories)
21 cal = A.sum(axis=0)
22 print (cal)
23 percentage = 100*A/cal.reshape(1,4)
24 print (percentage)
19 25
20 if __name__ == '__main__': 26 if __name__ == '__main__':
21 unittest.main() 27 unittest.main()