I started learning about ML and wanted to create a layer consisting of 3 Neurons and a small batch of inputs in Python.I use Numpy to calculate the dotproduct of two matrices.
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)
But somehow eventhough i transpose the matrix b i end up with a shape error
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)
CodePudding user response:
You have two rows with 5 instead of 4 elements in a, probably you meant 1.5
, and 0.8
instead of 1,5
and 0,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