Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions homework/m1_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
def green_mean():
"""建立 [10, 20, 30, 40, 50],回傳所有元素的平均值 (float)"""
# TODO: 你的程式碼
return np.mean([10, 20, 30, 40, 50], dtype=np.float32)
pass


def green_double():
"""建立 [10, 20, 30, 40, 50],回傳所有元素乘以 2 的 ndarray"""
# TODO: 你的程式碼
return np.array([10, 20, 30, 40, 50]) * 2
pass


def green_filter():
"""建立 [10, 20, 30, 40, 50],回傳大於 25 的元素 (ndarray)"""
# TODO: 你的程式碼
a = np.array([10, 20, 30, 40, 50])
return a[a > 25]
pass


Expand All @@ -42,6 +46,7 @@ def green_filter():
def yellow_expensive_count(prices):
"""回傳單價 > 1000 的商品數量 (int)"""
# TODO: 你的程式碼
return len(prices[prices > 1000])
pass


Expand All @@ -51,6 +56,7 @@ def yellow_top3_stock_indices(stocks):
提示:np.argsort
"""
# TODO: 你的程式碼
return np.argsort(stocks)[-3:][::-1]
pass


Expand All @@ -60,6 +66,7 @@ def yellow_restock_cost(prices, stocks):
提示:布林遮罩 + .sum()
"""
# TODO: 你的程式碼
return np.sum(np.array(prices[prices < 500]) * 50)
pass


Expand All @@ -77,4 +84,5 @@ def red_double11_prices(prices, stocks):
提示:np.where 可以巢狀使用
"""
# TODO: 你的程式碼
return np.where(stocks >= 100, prices * 0.7, np.where(stocks >= 20, prices * 0.9, prices))
pass
Loading