Say I have matrices A and B.
A is a three dimensional array/tensor(?).
[1,2,3,4]
[5,6,7,8]
[1,2,3,4]
[5,6,7,8]
There are say 4 DIFFERENT 2d matrices like the one above across the third dimension.
B is a matrix.
[1,2,3,4]
There are also 4 of of these in B, each one is the SAME.
How would I multiply each vector(?) in B with each 2d matrix in A.
[1,2,3,4]*[1,2,3,4]*[1;2;3;4]
[5,6,7,8]
[1,2,3,4]
[5,6,7,8]
There would be four of the above type multiplications to get four 4x1 vectors. I've tried it with numpy as:
y = numpy.arange(4).reshape(1,4)
z = numpy.arange(64).reshape(4,4,4)
y.dot(z).dot(numpy.transpose(y))
------
Output:
array([[[ 420],
[ 996],
[1572],
[2148]]])
And it works as I want it to. But I have no idea how numpy is broadcasting and I want to know for learning purposes and also other packages for dealing with matrices in different libraries handle broadcasting differently. I've tried to tile B in different ways to achieve the same results, but nothing works. If I'm not explaining anything clearly, let me know.
Also would prefer to get 4x1 rather than 3d return from numpy.