I am desperately trying to multiply a vector with a matrix. The problem is that the python console shows me this error:
ValueError: operands could not be broadcast together with shapes (4,20) (4,2)
I tried a solution from Stackoverflow and it did work but not for my matrix and vector.
My arrays that do not work:
a = np.array([[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]])
b = np.array([1, 5, 10, 22])
solution = a*b
My expected solution should look like this:
[[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[5, 5, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 22, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0]]
The arrays that works:
a = np.array([[3,2], [4, 5],[1,3]])
b = np.array([2, 4, 1])
solution = a*b
I do not know what is wrong with my two arrays.