[Numpy-discussion] Array of matrices - Inverse and dot
Tom K.
tpk at kraussfamily.org
Mon Jan 26 13:18:09 EST 2009
Jean-Baptiste Rudant wrote:
>
> I would like to operate in an easy and efficient way (without python loop)
> with arrays of matrices.
>
> Suppose a and b are some arrays of N1*N2 matrices of size 3*3, I would
> like to calculate inv_a and dot_ab, which would be arrays of N1*N2
> (3*3)-matrices, such as :
>
> inv_a[i, j] = np.linalg.inv(a[i, j])
> dot_ab[i, j] = np.dot(a[i, j], b[i, j])
>
> (where a and b could be :
> N1 = 5
> N2 = 6
> a = np.random((N1, N2, 3, 3)
> b = np.random((N1, N2, 3, 3)
> ).
>
Here's a one-liner:
numpy.array(map(numpy.dot, a, b))
that works for matrix multiply if a, b are (n, 3, 3). Could do the same for
linalg.inv.
This comes up a lot in OFDM MIMO systems so I wrote C++ code for complex
matrix multiply (arbitrary size), 2x2 complex inverse and 2x2 complex matrix
singular values, and then swigged it. I know a colleague at work has
extended this work to arbitrary size inverse. I wish I could share the code
but it is something developed for my company which has fairly strict
policies about posting these things (not worth the red-tape)...
I vote "+1" for such features in Numpy. I haven't looked too much "under
the hood" of numpy so I am not sure how you would do it or how hard it would
be.
Regards,
Tom K.
--
View this message in context: http://www.nabble.com/Array-of-matrices---Inverse-and-dot-tp21666949p21670624.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list