跨列廣播(Broadcasting across rows)
在上一組練習中,你使用了 monthly_industry_multipliers 來建立銷售預測。回想一下,monthly_industry_multipliers 的內容如下:
array([[0.98, 1.02, 1. ],
[1.00, 1.01, 0.97],
[1.06, 1.03, 0.98],
[1.08, 1.01, 0.98],
[1.08, 0.98, 0.98],
[1.1 , 0.99, 0.99],
[1.12, 1.01, 1. ],
[1.1 , 1.02, 1. ],
[1.11, 1.01, 1.01],
[1.08, 0.99, 0.97],
[1.09, 1. , 1.02],
[1.13, 1.03, 1.02]])
假設你不想讓估計值這麼細。你反而想用 monthly_industry_multipliers 找出每個產業的一個平均倍數,然後用這個倍數來推估明年的銷售額。
numpy 已以 np 名稱載入,monthly_sales 與 monthly_industry_multipliers 陣列也已可用。monthly_sales 的欄位依序代表酒類商店、餐廳與百貨公司的銷售額。
本練習屬於課程
NumPy 入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Find the mean sales projection multiplier for each industry
mean_multipliers = ____
print(mean_multipliers)