3x4 矩阵的点积

Dotproduct of 3x4 matrices

我开始学习 ML,想创建一个由 3 个神经元和一小批输入组成的层 Python.I 使用 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)

但不知何故,尽管我转置了矩阵 b,但最终出现了形状错误

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)

你有两行,a 中有 5 个而不是 4 个元素,可能你的意思是 1.50.8 而不是 1,50,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