numpy help

Robert Kern robert.kern at gmail.com
Sat Nov 4 01:48:32 EST 2006


Chris Smith wrote:
> Howdy,
> 
> I'm a college student and for one of we are writing programs to
> numerically compute the parameters of antenna arrays. I decided to use
> Python to code up my programs. Up to now I haven't had a problem,
> however we have a problem set where we are creating a large matrix and
> finding it's inverse to solve the problem. To invert the matrix I've
> tried using numpy.numarray.linear_algebra.inverse and
> numpy.oldnumeric.linear_algebra.inverse which both give me the same
> error ( I was hoping they called different routines but I think they
> call the same one ).

You will want to ask numpy questions on the numpy mailing list, not here.

  http://www.scipy.org/Mailing_Lists

Both of the functions that you mention are compatibility functions for
transitioning code that used to use Numeric or numarray to numpy. Do not use
them in new code. The function you want is numpy.linalg.pinv().

> I've tried inverting small complex matrices and it worked fine. Does
> anyone know why it won't work for this larger matrix? Any ideas how I
> can work around this problem and get the correct inverse matrix?

Please cut your examples down to the smallest piece of self-contained code that
demonstrates the problem. Not only does that make it easier for us to give you
an answer, during the process, you will often locate and fix the problem yourself.

However, I believe your problem is in your BlockToeplitz function. You create an
array using the following:

      matrix = numpy.zeros((2*M*N,2*M*N), dtype = type(a))

You are passing in a list as the argument a. The above line will create an
object array which is not what you want. Since linalg.pinv() will eventually
call a LAPACK function which only knows about floats and complex floats, it
refuses the temptation to guess what you meant and raises an error.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list