{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "2ee836bb", "metadata": { "id": "2ee836bb" }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "markdown", "id": "62d1ec97", "metadata": { "id": "62d1ec97" }, "source": [ "# Numpy Excersise" ] }, { "cell_type": "markdown", "id": "0f8fcf8d", "metadata": { "id": "0f8fcf8d" }, "source": [ "本次測驗分為兩個部分:\n", "\n", "1. Python 基礎\n", "2. Numpy 基礎\n", "\n", "兩個部分各 4 題,請善用工具及提示。**google 是你的一個好幫手**,如果有任何問題不妨參考前人的智慧,若有任何問題,也可隨時向助教尋求幫助。" ] }, { "cell_type": "markdown", "id": "a7be8000", "metadata": { "id": "a7be8000" }, "source": [ "# Python 基礎" ] }, { "cell_type": "markdown", "id": "73e9f59d", "metadata": { "id": "73e9f59d" }, "source": [ "## 1. 質數判斷" ] }, { "cell_type": "markdown", "id": "fc04ae23", "metadata": { "id": "fc04ae23" }, "source": [ "**請定義一函式 prime ,輸入為一整數,該函式檢查數字是否為質數。**\n", "\n", "(若 \"是\",回傳 **True**;反之,則回傳 **False**。)" ] }, { "cell_type": "code", "execution_count": 2, "id": "bc8c2a0a", "metadata": { "id": "bc8c2a0a" }, "outputs": [], "source": [ "def prime(number):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. number:一整數,用於判斷是否為整數\n", " '''\n", " if number == 2:\n", " return True\n", " elif (number < 2) or (number % 2 == 0):\n", " return False\n", " for i in range(3, number//2+1, 2):\n", " if number%i == 0:\n", " return False\n", " return True" ] }, { "cell_type": "code", "execution_count": 3, "id": "1ebcaf20", "metadata": { "id": "1ebcaf20" }, "outputs": [], "source": [ "# validation cell, do not modifiy this cell\n", "assert prime(-17) == False\n", "assert prime(0) == False\n", "assert prime(2) == True\n", "assert prime(6) == False\n", "assert prime(17) == True" ] }, { "cell_type": "markdown", "id": "872e4622", "metadata": { "id": "872e4622" }, "source": [ "## 2. 購物清單" ] }, { "cell_type": "markdown", "id": "1c989976", "metadata": { "id": "1c989976" }, "source": [ "給定一購物清單 shopping_list,當中包含多個 list。\n", "\n", "每個 list 都存有一日期、購物項目;每個購物項目皆為三元組,依序為品項、數量、價格。\n", "\n", "**請幫忙將購物清單整理成 dictionary 的格式,並用以下格式輸出:**\n", "\n", "* **dictionary 格式:(注意:該字典格式為 \"三層\" 結構)**\n", "\n", "\n", "\n", "* **輸出格式**\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "source": [ "# define variable cell, do not modifiy this cell\n", "shopping_list = [['2020.01/24', ('milk', 15, 129.0), ('noodle', 1, 70.0), ('candy', 10, 2.5)],\n", " ['2020.02/24', ('milk', 15, 129.0), ('noodle', 3, 70.0), ('candy', 10, 2.5)],\n", " ['2020.02/24', ('milk', 4, 129.0), ('meat', 2, 499.5), ('cookie', 10, 3)],\n", " ['2022/12-25', ('milk', 15, 129.0), ('coffee', 5, 25), ('cookie', 15, 3), ('meat', 10, 499.5)],\n", " ['2023-12/26', ('coffee', 7, 25), ('noodle', 2, 70.0), ('candy', 15, 2.5)]]" ], "metadata": { "id": "T6MzqGkKo-Sm" }, "id": "T6MzqGkKo-Sm", "execution_count": 4, "outputs": [] }, { "cell_type": "code", "execution_count": 5, "id": "7fac6a86", "metadata": { "id": "7fac6a86" }, "outputs": [], "source": [ "# writting your answer here\n", "\n", "shopping_dic = {}\n", "for l in shopping_list:\n", " data = l[0]\n", " date = data[:4]+' 年 '+data[5:7]+' 月 '+data[-2:]+' 日'\n", " if date not in shopping_dic:\n", " shopping_dic[date]={}\n", " for item in l[1:]:\n", " if item[0] not in shopping_dic[date]:\n", " shopping_dic[date][item[0]] = {}\n", " shopping_dic[date][item[0]]['amount'] = item[1]\n", " shopping_dic[date][item[0]]['price'] = item[2]\n", " continue\n", " shopping_dic[date][item[0]]['amount'] += item[1]" ] }, { "cell_type": "code", "execution_count": 6, "id": "66a05b0c", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "66a05b0c", "outputId": "5fb86d9a-3836-407e-e58b-689fdb05a196" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{'2020 年 01 月 24 日': {'milk': {'amount': 15, 'price': 129.0},\n", " 'noodle': {'amount': 1, 'price': 70.0},\n", " 'candy': {'amount': 10, 'price': 2.5}},\n", " '2020 年 02 月 24 日': {'milk': {'amount': 19, 'price': 129.0},\n", " 'noodle': {'amount': 3, 'price': 70.0},\n", " 'candy': {'amount': 10, 'price': 2.5},\n", " 'meat': {'amount': 2, 'price': 499.5},\n", " 'cookie': {'amount': 10, 'price': 3}},\n", " '2022 年 12 月 25 日': {'milk': {'amount': 15, 'price': 129.0},\n", " 'coffee': {'amount': 5, 'price': 25},\n", " 'cookie': {'amount': 15, 'price': 3},\n", " 'meat': {'amount': 10, 'price': 499.5}},\n", " '2023 年 12 月 26 日': {'coffee': {'amount': 7, 'price': 25},\n", " 'noodle': {'amount': 2, 'price': 70.0},\n", " 'candy': {'amount': 15, 'price': 2.5}}}" ] }, "metadata": {}, "execution_count": 6 } ], "source": [ "shopping_dic" ] }, { "cell_type": "code", "execution_count": 7, "id": "c9b50163", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "c9b50163", "outputId": "ca5bc821-e30d-464c-fc64-d80ee563ab9a" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "2020 年 01 月 24 日\n", " milk: amount: 15.00 price :129.00 \t\n", " noodle: amount: 1.00 price : 70.00 \t\n", " candy: amount: 10.00 price : 2.50 \t\n", "購入產品 26 件,總共:2030.00\n", "\n", "2020 年 02 月 24 日\n", " milk: amount: 19.00 price :129.00 \t\n", " noodle: amount: 3.00 price : 70.00 \t\n", " candy: amount: 10.00 price : 2.50 \t\n", " meat: amount: 2.00 price :499.50 \t\n", " cookie: amount: 10.00 price : 3.00 \t\n", "購入產品 44 件,總共:3715.00\n", "\n", "2022 年 12 月 25 日\n", " milk: amount: 15.00 price :129.00 \t\n", " coffee: amount: 5.00 price : 25.00 \t\n", " cookie: amount: 15.00 price : 3.00 \t\n", " meat: amount: 10.00 price :499.50 \t\n", "購入產品 45 件,總共:7100.00\n", "\n", "2023 年 12 月 26 日\n", " coffee: amount: 7.00 price : 25.00 \t\n", " noodle: amount: 2.00 price : 70.00 \t\n", " candy: amount: 15.00 price : 2.50 \t\n", "購入產品 24 件,總共:352.50\n", "\n" ] } ], "source": [ "for date, products in shopping_dic.items():\n", " print(date)\n", " num, account = 0, 0\n", " for product, detail in products.items():\n", " print(f'{product:>8s}:', end = ' ')\n", " num += detail['amount']\n", " account += detail['amount']*detail['price']\n", " for key, val in detail.items():\n", " print(f'{key:6s}:{val:6.2f}', end = ' ')\n", " print('\\t')\n", " print(f'購入產品 {num} 件,總共:{account:.2f}\\n')" ] }, { "cell_type": "markdown", "id": "e708e566", "metadata": { "id": "e708e566" }, "source": [ "## 3. 捲積運算" ] }, { "cell_type": "markdown", "id": "f78f3df2", "metadata": { "id": "f78f3df2" }, "source": [ "捲積運算是透過一個較小的矩陣 (Filters,或稱卷積核 kernel),平移滑動數個位置 (stride) 在另一矩陣做 element-wise 的相乘並計算其總和得計算方式。 \n", "此方法常用在提取圖像的特徵 (稱作 Feature Map)。如下圖所示:\n", "\n", "\n", "\n", "**請試著定義一函式 convolution,輸入為一代表圖像的矩陣 (img) 和卷積核 (kernel),並回傳計算後的矩陣。平移數 (stride) 皆為 1。**" ] }, { "cell_type": "code", "source": [ "# define variable cell, do not modifiy this cell\n", "img = np.arange(1, 26, 1).reshape(5, 5)\n", "kernel = np.ones((3,3))" ], "metadata": { "id": "wuQR1rXep4fy" }, "id": "wuQR1rXep4fy", "execution_count": 8, "outputs": [] }, { "cell_type": "code", "execution_count": 9, "id": "c99cc224", "metadata": { "id": "c99cc224" }, "outputs": [], "source": [ "def convolution(img, kernel):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. img:一個 np.array 的矩陣。\n", " 2. kernel:一個 np.array 的矩陣,用來遍歷 img 並計算結果。\n", " '''\n", " img_size = img.shape[0]\n", " kernel_size = kernel.shape[0]\n", " print(f'img_size:{img_size}, kernel_size:{kernel_size}')\n", " new_img_size = img_size - kernel_size + 1\n", " new_img = np.zeros((new_img_size, new_img_size))\n", "\n", " for i in range(new_img_size):\n", " for j in range(new_img_size):\n", " print(f'{i}, {j}')\n", " value = 0\n", " for ki in range(kernel_size):\n", " for kj in range(kernel_size):\n", " value += img[i+ki][j+kj] * kernel[ki][kj]\n", " new_img[i][j] = value\n", " return new_img" ] }, { "cell_type": "code", "execution_count": 10, "id": "5b34277a", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5b34277a", "outputId": "a0c5c5da-f7ca-4c4b-aaf8-fe347df3842f" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "img_size:5, kernel_size:3\n", "0, 0\n", "0, 1\n", "0, 2\n", "1, 0\n", "1, 1\n", "1, 2\n", "2, 0\n", "2, 1\n", "2, 2\n" ] } ], "source": [ "# validation cell, do not modifiy this cell\n", "img = np.arange(1, 26, 1).reshape(5, 5)\n", "kernel = np.ones((3,3))\n", "assert (convolution(img, kernel) == [[ 63., 72., 81.],\n", " [108., 117., 126.],\n", " [153., 162., 171.]]).all()" ] }, { "cell_type": "markdown", "id": "e0184629", "metadata": { "id": "e0184629" }, "source": [ "## 4. 凱薩加密" ] }, { "cell_type": "markdown", "id": "19c9492f", "metadata": { "id": "19c9492f" }, "source": [ "凱薩加密是一種簡單且廣為人知的替換加密技術。\n", "明文 (原始文本) 中的所有字母都在字母表上向後(或向前)按照一個固定數目進行偏移後被替換成密文 (加密後的文本)。\n", "這偏移量便是加密技術中所謂的金鑰 (key),若沒有金鑰便難以進行解密的動作。\n", "\n", "**請試著定義一個函式 caesar 符合凱薩加密的方法,輸入參數分別為密文(ciphertext)以及金鑰(key),並返回明文。**\n", "\n", "\n", "\n", "**hint: 該題只考慮小寫字母 (a ~ z),不做特殊符號的處理**" ] }, { "cell_type": "code", "execution_count": 11, "id": "2cf6ded6", "metadata": { "id": "2cf6ded6" }, "outputs": [], "source": [ "def caesar(ciphertext, key):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. ciphertext:密文\n", " 2. key:金鑰\n", " '''\n", " words = [ord(i) for i in ciphertext]\n", " key %= 26\n", " for i, _ in enumerate(words):\n", " if ord('a') <= words[i] <= ord('z'):\n", " words[i] = words[i] - key\n", " if words[i] < ord('a'):\n", " words[i] += 26\n", " elif words[i] > ord('z'):\n", " words[i] -= 26\n", " context = ''\n", " for i in words:\n", " context += chr(i)\n", " print(context)\n", " return context" ] }, { "cell_type": "code", "execution_count": 12, "id": "2d191d30", "metadata": { "id": "2d191d30", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "ff2fe83e-ca85-441c-95aa-3713acb141fa" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "hello world\n", "ai academy\n", "have a nice day.\n" ] } ], "source": [ "# validation cell, do not modifiy this cell\n", "assert caesar('tqxxa iadxp', 12) == 'hello world'\n", "assert caesar('em egehiqc', 56) == 'ai academy'\n", "assert caesar('fytc y lgac byw.', 24) == 'have a nice day.'" ] }, { "cell_type": "markdown", "id": "c66b93a4", "metadata": { "id": "c66b93a4" }, "source": [ "# Numpy 基礎" ] }, { "cell_type": "markdown", "id": "ccae13bc", "metadata": { "id": "ccae13bc" }, "source": [ "## 5. 維度" ] }, { "cell_type": "markdown", "id": "f4726fcf", "metadata": { "id": "f4726fcf" }, "source": [ "有兩陣列 $a$、$b$。$a$ 為一存放兩筆資料的陣列;$b$ 表示 $a$ 的資料分別需要乘上多少倍率。\n", "\n", "**請透過兩種方式:**\n", "\n", "**1. 函式 method_1 使用 reshape。**\n", "\n", "**2. 函式 method_2 使用 squeeze 、 expand_dims。**\n", "\n", "**使得 $a$ x $b$ 符合題目要求。**" ] }, { "cell_type": "code", "execution_count": 13, "id": "1cf67491", "metadata": { "id": "1cf67491" }, "outputs": [], "source": [ "# define variable cell, do not modifiy this cell\n", "a = np.array([[[[1, 2, 3, 4],\n", " [1, 2, 3, 4],\n", " [1, 2, 3, 4]]],\n", " [[[1, 2, 3, 4],\n", " [1, 2, 3, 4],\n", " [1, 2, 3, 4]]]])\n", "b = np.array([[1], [2]])" ] }, { "cell_type": "code", "execution_count": 14, "id": "c275f0e5", "metadata": { "id": "c275f0e5" }, "outputs": [], "source": [ "def method_1(a, b):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. a、b:皆一個 np.array 的矩陣,試著完成題目要求。\n", " '''\n", " return a * b.reshape(2, 1, 1, 1)" ] }, { "cell_type": "code", "execution_count": 15, "id": "68bc314f", "metadata": { "id": "68bc314f" }, "outputs": [], "source": [ "def method_2(a, b):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. a、b:皆一個 np.array 的矩陣,試著完成題目要求。\n", " '''\n", " return a * np.expand_dims(np.expand_dims(b, 1), 1)" ] }, { "cell_type": "code", "execution_count": 16, "id": "8a2020e5", "metadata": { "id": "8a2020e5" }, "outputs": [], "source": [ "# validation cell, do not modifiy this cell\n", "assert (method_1(a, b) == [[[[1, 2, 3, 4],[1, 2, 3, 4],[1, 2, 3, 4]]],\n", " [[[2, 4, 6, 8],[2, 4, 6, 8],[2, 4, 6, 8]]]]).all()\n", "\n", "assert (method_2(a, b) == [[[[1, 2, 3, 4],[1, 2, 3, 4],[1, 2, 3, 4]]],\n", " [[[2, 4, 6, 8],[2, 4, 6, 8],[2, 4, 6, 8]]]]).all()" ] }, { "cell_type": "code", "execution_count": 17, "id": "b47ed71a", "metadata": { "id": "b47ed71a" }, "outputs": [], "source": [ "def method_1(a, b):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. a、b:皆一個 np.array 的矩陣,試著完成題目要求。\n", " '''\n", " return a.reshape(2, 3, 4) * b.reshape(2, 1, 1)" ] }, { "cell_type": "code", "execution_count": 18, "id": "46eafa62", "metadata": { "id": "46eafa62" }, "outputs": [], "source": [ "def method_2(a, b):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. a、b:皆一個 np.array 的矩陣,試著完成題目要求。\n", " '''\n", " return np.squeeze(a) * np.expand_dims(b, 1)" ] }, { "cell_type": "code", "execution_count": 19, "id": "4c3c4763", "metadata": { "id": "4c3c4763" }, "outputs": [], "source": [ "# validation cell, do not modifiy this cell\n", "assert (method_1(a, b) == [[[1, 2, 3, 4],[1, 2, 3, 4],[1, 2, 3, 4]],\n", " [[2, 4, 6, 8],[2, 4, 6, 8],[2, 4, 6, 8]]]).all()\n", "\n", "assert (method_2(a, b) == [[[1, 2, 3, 4],[1, 2, 3, 4],[1, 2, 3, 4]],\n", " [[2, 4, 6, 8],[2, 4, 6, 8],[2, 4, 6, 8]]]).all()" ] }, { "cell_type": "markdown", "id": "337ef2e7", "metadata": { "id": "337ef2e7" }, "source": [ "## 6. 維度擴充並重複填充" ] }, { "cell_type": "markdown", "id": "14ce53b2", "metadata": { "id": "14ce53b2" }, "source": [ "在後續的深度學習課程,我們可能在處理數據的時候碰到某些情況\n", "\n", "**透過一個 $n$ 維數組來與另一個 $n+1$ 維數組做一對一運算**\n", "\n", "這時候該怎麼辦呢?我們會需要先將 $n$ 維數組填充成 $n+1$ 維數組,並重複 $k$ 次。\n", "\n", "如: \n", "一個 $n$ 維數組,填充第 1 維度成 $n+1$ 維,並重複 4 次\n", "\n", "\n", "\n", "一個 $n$ 維數組,填充第 2 維度成 $n+1$ 維,並重複 4 次\n", "\n", "\n", "\n", "**請試著定義一函式 expand,輸入為一陣列 (array) 、維度 (axis)、和次數 (k),可以透過參數改變需要填充的維度以及重複的次數,並回傳結果。**" ] }, { "cell_type": "code", "execution_count": 20, "id": "3e300b02", "metadata": { "id": "3e300b02" }, "outputs": [], "source": [ "# define variable cell, do not modifiy this cell\n", "a = np.array([[1, 2, 3], [2, 4, 6]])" ] }, { "cell_type": "code", "execution_count": 21, "id": "59fe7ba5", "metadata": { "id": "59fe7ba5" }, "outputs": [], "source": [ "def expand(array, axis, k):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. array:一個 np.array 的矩陣。\n", " 2. axis:需要填充的維度。\n", " 3. k:需要重複的次數。\n", " '''\n", " return np.expand_dims(array, axis).repeat(k, axis)" ] }, { "cell_type": "code", "execution_count": 22, "id": "2ea69f80", "metadata": { "id": "2ea69f80" }, "outputs": [], "source": [ "assert (expand(a, 0, 4)==np.array([[[1, 2, 3], [2, 4, 6]], [[1, 2, 3], [2, 4, 6]],\n", " [[1, 2, 3], [2, 4, 6]], [[1, 2, 3], [2, 4, 6]]])).all() # 注意,填充第幾個維度是從零開始算\n", "assert (expand(a, 1, 4)==[[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]],\n", " [[2, 4, 6], [2, 4, 6], [2, 4, 6], [2, 4, 6]],]).all() # 注意,填充第幾個維度是從零開始算" ] }, { "cell_type": "code", "execution_count": 23, "id": "8644b526", "metadata": { "id": "8644b526", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "a82ad752-ff7a-4285-bb44-3df4f4c20e09" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "array([[[1, 2, 3],\n", " [1, 2, 3],\n", " [1, 2, 3],\n", " [1, 2, 3]],\n", "\n", " [[2, 4, 6],\n", " [2, 4, 6],\n", " [2, 4, 6],\n", " [2, 4, 6]]])" ] }, "metadata": {}, "execution_count": 23 } ], "source": [ "expand(a, 1, 4) # 注意,填充第幾個維度是從零開始算" ] }, { "cell_type": "markdown", "id": "01246109", "metadata": { "id": "01246109" }, "source": [ "## 7. 矩陣總和" ] }, { "cell_type": "markdown", "id": "968e8821", "metadata": { "id": "968e8821" }, "source": [ "**請試著定義一函式 matrixElementsSum,輸入為一矩陣 (X),計算矩陣中所有數字的總和,若該值的上方 \"出現過\" 0,則不予計算**\n", "\n", "例如:一矩陣如圖\n", "\n", "\n", "\n", "由於紅色數字上方皆沒有 0 出現,故總數為 1 + 2 + 3 + 5 = 11 \n", "因此輸出應為:matrixElementsSum(matrix) = 11\n", "\n", "**hint:np.where、.item、.itemset**" ] }, { "cell_type": "code", "source": [ "# define variable cell, do not modifiy this cell\n", "matrix_X = [[0, 1, 2, 3],\n", " [4, 5, 0, 0],\n", " [6, 0, 7, 8]]" ], "metadata": { "id": "d2swtcasq4uQ" }, "id": "d2swtcasq4uQ", "execution_count": 24, "outputs": [] }, { "cell_type": "code", "execution_count": 25, "id": "2f3688bb", "metadata": { "id": "2f3688bb" }, "outputs": [], "source": [ "def matrixElementsSum(M):\n", " # writting your answer here\n", " '''\n", " input parameter:\n", " 1. M:一個 np.array 的矩陣。是求出題目要求。\n", " '''\n", " array = np.array(M)\n", " print(array)\n", " zero_index = np.where(array==0)\n", " print(f\"zero_index:{zero_index}\")\n", "\n", " zero_count = len(zero_index[0])\n", " print(f'zero_count:{zero_count}')\n", "\n", " array_rows, _ = array.shape\n", " print(f\"array_rows:{array_rows}\")\n", "\n", " for i in range(zero_count):\n", " y, x = zero_index\n", " y_index = y[i]\n", " x_index = x[i]\n", " print(f'x_index:{x_index}, y_index:{y_index}')\n", "\n", " while y_index < array_rows:\n", " print(f'array_rows:{array_rows}, y_index:{y_index}, x_index:{x_index}')\n", " array.itemset((y_index,x_index),0)\n", " y_index+=1\n", " total = np.sum(array)\n", " return total" ] }, { "cell_type": "code", "execution_count": 26, "id": "dae5838a", "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dae5838a", "outputId": "5968e374-b4da-475e-d534-149a552f21c0" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[[0 1 2 3]\n", " [4 5 0 0]\n", " [6 0 7 8]]\n", "zero_index:(array([0, 1, 1, 2]), array([0, 2, 3, 1]))\n", "zero_count:4\n", "array_rows:3\n", "x_index:0, y_index:0\n", "array_rows:3, y_index:0, x_index:0\n", "array_rows:3, y_index:1, x_index:0\n", "array_rows:3, y_index:2, x_index:0\n", "x_index:2, y_index:1\n", "array_rows:3, y_index:1, x_index:2\n", "array_rows:3, y_index:2, x_index:2\n", "x_index:3, y_index:1\n", "array_rows:3, y_index:1, x_index:3\n", "array_rows:3, y_index:2, x_index:3\n", "x_index:1, y_index:2\n", "array_rows:3, y_index:2, x_index:1\n" ] } ], "source": [ "assert matrixElementsSum(matrix_X) == 11" ] } ], "metadata": { "colab": { "provenance": [], "toc_visible": true }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.12" } }, "nbformat": 4, "nbformat_minor": 5 }