From 4b7eaff8735c131f0d3bcdc8b9c627d6fc1af90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AC=9D=E7=BF=94=E5=AE=87?= Date: Mon, 4 May 2026 00:08:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20M1=20=E4=BD=9C=E6=A5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homework/m1_numpy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homework/m1_numpy.py b/homework/m1_numpy.py index 5ff41ab..89a5eda 100644 --- a/homework/m1_numpy.py +++ b/homework/m1_numpy.py @@ -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 @@ -42,6 +46,7 @@ def green_filter(): def yellow_expensive_count(prices): """回傳單價 > 1000 的商品數量 (int)""" # TODO: 你的程式碼 + return len(prices[prices > 1000]) pass @@ -51,6 +56,7 @@ def yellow_top3_stock_indices(stocks): 提示:np.argsort """ # TODO: 你的程式碼 + return np.argsort(stocks)[-3:][::-1] pass @@ -60,6 +66,7 @@ def yellow_restock_cost(prices, stocks): 提示:布林遮罩 + .sum() """ # TODO: 你的程式碼 + return np.sum(np.array(prices[prices < 500]) * 50) pass @@ -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