Mercurial > hg > tvii
view tests/test_broadcasting.py @ 21:0149be5a984c
[iterable] add function to tell True/False if argument is an iterable
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 04 Sep 2017 08:37:06 -0700 |
parents | 926c127305fa |
children |
line wrap: on
line source
#!/usr/bin/env python """ illustration of numpy broadcasting """ import os import unittest import numpy as np #apples, beef, eggs, potatos calories = [[56., 0.0, 4.4, 68.], # carbs [1.2, 104., 52., 8.], # protein [1.8, 135., 99., 0.9]] # fat class TestBroadcasting(unittest.TestCase): def test_basic(self): """example of broadcasting""" A = np.array(calories) cal = A.sum(axis=0) print (cal) percentage = 100*A/cal.reshape(1,4) print (percentage) if __name__ == '__main__': unittest.main()