[SciPy-user] Matrix Multiply for > 2 dim matricies?
Gregory Novak
novak at ucolick.org
Mon Jan 30 23:30:23 CST 2006
I'm somewhat mystified by the behavior of the matrix multiply routine
for > 2d matricies.
The back story: at every point on a 3d grid, I have a vector and I
would like to apply a matrix transformation to all of them. I had
thought that by feeding the matrix and the whole 4d array to
matrixmultiply, I'd be able to quickly do this. However, I had
trouble figuring out how to correctly interpret the output from
matrixmultiply.
After exhaustively feeding 2x2x2 arrays to matrix multiply to see if I
could tease out the correct behavior, I found that A =
matrixmultiply(B,C) means that:
A_ij0k = B_ijn C_0nk
But when the first index of C is 1, I don't see what's going on. For
example, it seems that:
A_0010 = B_000 * C_010 + B_001 * C_100
Ie, for either:
B = zeros((2,2,2)); C = zeros((2,2,2))
B[0,0,0] = 1
C[0,1,0] = 1
A = matrixmultiply(B,C)
or:
B = zeros((2,2,2)); C = zeros((2,2,2))
B[0,0,1] = 1
C[1,0,0] = 1
A = matrixmultiply(B,C)
A ends up being the same, namely:
[[[[0,0,]
[1,0,]]
[[0,0,]
[0,0,]]]
[[[0,0,]
[0,0,]]
[[0,0,]
[0,0,]]]]
So, I know that matrixmultiply multiplies a bunch of things and adds
them together, but I'm having trouble deducing exactly _what_ it does
in this case.
Thanks,
Greg
More information about the SciPy-user
mailing list