Skip to content

AI STUDIO Taiwan

台 灣 人 工 智 慧 與 資 料 科 學 研 究 室

  • About 關於本站
  • 專欄列表
  • Taiwan NLP.台灣自然語言處理與人工智慧交流社( 1.8萬位成員)
  • 關於 Taiwan NLP 社群

【機器學習數學基礎】01 矩陣計算

Posted on 2019 年 4 月 27 日2023 年 5 月 11 日 By 楊 明翰 在〈【機器學習數學基礎】01 矩陣計算〉中尚無留言
機器學習數學基礎
Print Friendly, PDF & Email

內容目錄

  • 矩陣係數積(Scalar Multiplication)
  • 矩陣乘積(Matrix Product)
  • 矩陣哈達瑪積(Matrix Hadamard Product),又稱逐元素積(Element-wise product or Point-wise product)

矩陣係數積(Scalar Multiplication)

矩陣的每一個元素乘上一個固定的數值,乘完之後矩陣大小不變

aX_{m,n}=\begin{bmatrix}
a \, x_{0,0} & a \, x_{0,1} & \cdots & a \, x_{1,n-1} \\
a \, x_{1,0} & a \, x_{1,1} & \cdots & a \, x_{2,n-1} \\
\vdots & \vdots & \ddots & \vdots \\
a \, x_{m-1,1} & a \, x_{m-1,2} & \cdots & a \, x_{m-1,n-1}
\end{bmatrix}

範例:

\begin{aligned}
	X=\begin{bmatrix}
	1&2&3  \\
	4&5&6
	\end{bmatrix}
	\\
	2X=\begin{bmatrix}
	2&4&6  \\
	8&10&12
	\end{bmatrix}
\end{aligned}

實驗程式碼

Python
import numpy as np
X=np.array([[1,2,3],[4,5,6]])
print(X)
X=2*X
print(X)

程式輸出:

[[1 2 3]
 [4 5 6]]
[[ 2  4  6]
 [ 8 10 12]]

矩陣乘積(Matrix Product)

矩陣乘積為一個矩陣的所有列(橫向)向量(Row Vector)逐一與另一個矩陣的所有行(直向)向量(column vector)作向量內積所形成的矩陣。

\begin{aligned}
& Z=XY \\\\
&\begin{bmatrix}
    z_{00} & z_{01} & \cdots & z_{0\,p-1}\\
    z_{10} & z_{11} & \cdots & z_{1\,p-1}\\ 
    \vdots & \vdots & \ddots & \vdots\\ 
    z_{m-1\,0} & z_{m-1\,1} & \cdots & z_{m-1\,p-1} 
\end{bmatrix}

=\\\\

& \begin{bmatrix}
    x_{00} & x_{01} & \cdots & x_{0\,n-1}\\
    x_{10} & x_{11} & \cdots & x_{1\,n-1}\\ 
    \vdots & \vdots & \ddots & \vdots\\ 
    x_{m-1\,0} & x_{m-1\,1} & \cdots & x_{m-1\,n-1} 
\end{bmatrix}
     \times
\begin{bmatrix}
    y_{00} & y_{01} & \cdots & y_{0\,p-1}\\
    y_{10} & y_{11} & \cdots & y_{1\,p-1}\\ 
    \vdots & \vdots & \ddots & \vdots\\ 
    y_{n-1\,0} & y_{n-1\,1} & \cdots & y_{n-1\,p-1} 
\end{bmatrix}
\end{aligned}

矩陣Z的每個元素為:

z_{m p}= x_{m0}\times y_{0p} + x_{m1} \times y_{1p} +\cdots+ x_{m\,n-1}\times y_{n-1\,p} = \sum_{k=0}^{n-1} x_{mk} \times y_{kp} 

計算範例:

\begin{aligned}
	X=\begin{bmatrix}
	1&2&3  \\
	4&5&6
	\end{bmatrix}
	\\
	
	Y=\begin{bmatrix}
	5&6&7  \\
	8&9&10  \\
        11&12&13  \\
	\end{bmatrix}
	\\

\end{aligned}

則矩陣乘法的結果,其矩陣第一個位置為X的第一個列向量與Y的第一個行向量的內積,也就是:

\begin{aligned}
Z_{00}=(1\; 2\; ,3 ) \cdot  ( 5\;,8\; ,11 )=1\times  5+2\times  8+3\times 11=5+16+33=54

\end{aligned}

類似的有:

\begin{aligned}
Z_{01}=(1\; 2\; ,3 )  \cdot  ( 6\;,9\; ,12 )=1\times  6+2\times  9+3\times 12=6+18+36=60 \\

Z_{02}=(1\; 2\; ,3 )  \cdot   ( 7\;,10\; ,13 )=1\times  7+2\times  10+3\times 13=7+20+39=66 \\

Z_{10}=(4\;, 5\;, 6)  \cdot   ( 5\;,8\; ,11 )=4\times  5+5\times  8+6\times 11=20+40+66=126 \\

\end{aligned}

實驗程式碼

Python
import numpy as np
X=np.array([[1,2,3],[4,5,6]])
Y=np.array([[5,6,7],[8,9,10],[11,12,13]])
print(X)
print(Y)
Z=X.dot(Y)
print(Z)

輸出

[[1 2 3]
 [4 5 6]]
[[ 5  6  7]
 [ 8  9 10]
 [11 12 13]]
[[ 54  60  66]
 [126 141 156]]

矩陣哈達瑪積(Matrix Hadamard Product),又稱逐元素積(Element-wise product or Point-wise product)

兩矩陣的對應元素位置相乘的結果,也會是一個矩陣。

✔ 幫我們按個喜歡和分享,支持我們

平均分數 0 / 5. 給分人數 0

尚未有評分,請幫我評分歐

楊 明翰
楊 明翰

是一名八年級中段班的創業者與資料科學家

“With belief and action, we change the world.”

憑藉信念與行動,我們改變世界💪

更多關於站長

本文允許重製、散布、傳輸以及修改,但不得為商業目的之使用

使用時必須註明出處自:楊明翰 , 台灣人工智慧與資料科學研究室 https://aistudio.tw

標籤: matrix 矩陣 線性代數

文章導覽

❮ Previous Post: 【自然語言處理與理解】NLP斷詞與詞形還原
Next Post: 【站長哲學】人的一生時間其實不長 ❯

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

更多AI相關資訊,歡迎加入站長的粉絲團

Facebook

閱讀視覺風格選擇


實驗袍白 / 適合資料分析師、科學家
終端機黑 / 適合黑客、電腦工程師

專欄列表

  • Artificial intelligence 人工智慧 (3)
    • HPC 高效能運算 (1)
    • PyTorch (1)
    • 從頭實作AI (1)
  • Backend 後端開發 (1)
  • C++ 應用 (2)
  • Community 社群介紹 (1)
  • Data Engineering 資料工程與訊號分析 (1)
  • Java 開發與教學 (2)
  • Linux 入門 (5)
  • NLP/NLU 自然語言處理與理解 (4)
  • Philosophy 站長哲學 (5)
  • Python 開發與教學 (7)
    • Python Flask 網站開發 (1)
    • Python 中階 (1)
    • Python 入門 (5)
  • Slides會議簡報 (12)
  • Start-up 創新創業 (7)
  • 機器學習數學基礎 (1)
  • 私人筆記手稿 (4)
  • 線上教學目錄 (4)

近期發布

  • 【Linux 應用】使用Zenity零成本開發的多開瀏覽器管理器
  • 【Start-up 創新創業】如何選擇創業題目
  • 【自然語言處理與理解】Llama-2大語言模型CPU版本使用
  • 【個人演講】AI EXPO 2023 ChatGPT以及LLM
  • 【自訓課程】NGS 次世代基因體資料科學 課程

討論

尚無留言可供顯示。

年份彙整

  • 2023 (9)
  • 2022 (4)
  • 2021 (6)
  • 2020 (14)
  • 2019 (8)
  • 2018 (10)
  • 2017 (2)
  • 2016 (4)
  • 2015 (2)

ChatGPT GRU HPC llama-cpp LLM Log4J LSTM Node.js SMO SVM Zenity 人工智慧 人格特質 出資 創新 創業 多語言 多開瀏覽器 大語言模型 感知機 戰鬥 技術 技術合夥 技術股 撰寫程式 新創 新手 新聞輿情 最佳化 機器學習 死亡 現代C++ 系統日誌 股東權益 能力 證明 變數 負債 資本 資產負債表 長短期記憶 霍普菲爾 類神經網 類神經網路 風險

調整字型大小

A 縮小字型大小。 A 重設字型大小。 A 放大字型大小。

Copyright © 2023 AI STUDIO Taiwan.
聯絡我們 : whuang022@gmail.com
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Theme: Oceanly by ScriptsTown