1
votes

I have two matrices to multiply. One is the weight matrix W, whose size is 900x2x2. Another is input matrix I, whose size is 2x2.

I want to perform a summation over c = WI which will be a 900x1 matrix, but when I perform the operation it multiplies them and gives me a 900x2x2 matrix again.

Question #2 (related): So I made both of them 2D and multiplied 900x4 * 4x1, but that gives me an error saying:

ValueError: operands could not be broadcast together with shapes (900,4) (4,1)
1
I'm struggling to understand how you will get a 900x1 from a 900x2x2 and a 2x2. Am I missing something? Which one is W and which one is I? What is the domain of application (this might help)? - polarise
Its the summation of 2x2 * 2x2 for 900 weights. Just edited. You would have understood it better if you would have implemented ANN. - Hima

1 Answers

2
votes

It seems you are trying to lose the last two axes of the first array against the only two axes of the second weight array with that matrix-multiplication. We could translate that idea into NumPy code with np.tensordot and assuming arr1 and arr2 as the input arrays respectively, like so -

np.tensordot(arr1,arr2,axes=([1,2],[0,1]))

Another simpler way to put into NumPy code would be with np.einsum, like so -

np.einsum('ijk,jk',arr1,arr2)