Lets say, I have bunch of matrices As and vectors bs.
As = array([[[1, 7], [3, 8]],
[[2, 1], [5, 9]],
[[7, 2], [8, 3]]])
bs = array([[8, 0], [8, 8], [7, 3]])
When I do np.inner(As, bs), I get:
array([[[ 8, 64, 28], [ 24, 88, 45]],
[[ 16, 24, 17], [ 40, 112, 62]],
[[ 56, 72, 55], [ 64, 88, 65]]])
But I do not need all inner products. What I want is, to calculate each matrix with each vector once.
I can do something like this:
np.array(map(lambda (a, b): np.inner(a, b), zip(As, bs)))
Then I get the expected matrix:
array([[ 8, 24], [ 24, 112], [ 55, 65]])
Now I do not want to use zip, map etc. because I need this operation > 10**6 time (for image processing, exactly for GMM).
Is there any way to use numpy, scipy etc. that can do this for me? (fast and efficent)
See Question&Answers more detail:
os