開始使用免費開始

矩陣相乘

為了更直接理解矩陣相乘,讓我們手動做一些矩陣運算。

本練習屬於課程

使用 PySpark 打造推薦引擎

檢視課程

練習說明

  • 矩陣 ab 是 Pandas DataFrame。對它們各自使用 .head() 方法來檢視。
  • 自行算出這兩個矩陣的乘積。
  • ab 的乘積數值填入使用 np.array() 建立的 product 陣列中。
  • 使用最後一行程式碼的驗證來評估你的估計。.dot() 方法會將兩個矩陣相乘。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Use the .head() method to view the contents of matrices a and b
print("Matrix A: ")
print (a.____())

print("Matrix B: ")
print (b.____())

# Complete the matrix with the product of matrices a and b
product = np.array([[____,____], [____,____]])

# Run this validation to see how your estimate performs
product == np.dot(a,b)
編輯並執行程式碼