我開始學習 ML,并想在 Python 中創建一個由 3 個神經元和一小批輸入組成的層。我使用 Numpy 計算兩個矩陣的點積。
import numpy as np
a = [[1.7, 2.2, 3.1, 2.6],
[2.3, 5.8, -1,5, 2.6],
[-1.5, 2.7, 3.3, -0,8]]
b = [[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]]
c = [4.0,2.0,0.5]
output = np.dot(a, np.array(b).T) c
print(output)
但不知何故,即使我轉置矩陣 bi 最終出現形狀錯誤
line 16, in <module>
output = np.dot(a, np.array(b).T) c
File "<__array_function__ internals>", line 180, in dot
ValueError: shapes (3,) and (4,3) not aligned: 3 (dim 0) != 4 (dim 0)
uj5u.com熱心網友回復:
您有兩行,a 中有 5 個而不是 4 個元素,可能您的意思是1.5, 而0.8不是1,5and0,8
a = np.array([[1.7, 2.2, 3.1, 2.6],
[2.3, 5.8, -1.5, 2.6],
[-1.5, 2.7, 3.3, -0.8]])
b = np.array([[0.2, 0.8, -0.5, 1.0],
[0.5, -0.91, 0.26, -0.5],
[-0.26, -0.27, 0.17, 0.87]])
c = np.array([4.0,2.0,0.5])
np.dot(a, b.T) c
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/426283.html
