python 广播
"""
Calories from Carbs,Proteins,Fats in 100g of different foods:
Apples Beef Eggs Potatoes
Carb [94.91525424 0. 2.83140283 88.42652796]
Protein [ 2.03389831 43.51464435 33.46203346 10.40312094]
Fat [ 3.05084746 56.48535565 63.70656371 1.17035111]
Q:Calculate % of calories from Carbs,Proteins,Fats.Can you do this without
explicit for-loop?
"""
import numpy as np
A = np.array([[56.0,0.0,4.4,68.0],
[1.2,104.0,52.0,8.0],
[1.8,135.0,99.0,0.9]])
print(A)
cal = A.sum(axis=0)
print(cal)
percentage = 100*A/cal.reshape(1,4)
print(percentage)
参考吴恩达深度学习视频