[Numpy-discussion] Array of matrices - Inverse and dot

2009-01-26 Thread Jean-Baptiste Rudant
Hello,

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)
).

Thank you,

(Sorry to ask the list : I think it is quite a basic stuff, but searching for 
"array of matrices" on google didn't help me so much.)

Jean-Baptiste Rudant


  ___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Array of matrices - Inverse and dot

2009-01-26 Thread David Cournapeau
On Mon, Jan 26, 2009 at 11:59 PM, Jean-Baptiste Rudant
 wrote:
> Hello,
> 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 :

If you only care about 3*3 matrices, I would consider using
"developed" formula of a 3x3 matrix inverse coded in numpy. numpy.inv
will be quite slow for such small matrices anyway (all the machinery
to call the underlying C code being almost certainly the bottleneck).

David
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Array of matrices - Inverse and dot

2009-01-26 Thread Tom K.


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.

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion