using numpy to do linear algebra

Robert Kern robert.kern at gmail.com
Sat Feb 3 02:37:37 EST 2007


Michael O'Brien wrote:
> Hola~
> 
> I have a large array of points (over a million). I would like to
> multiply each point in the array by a 4x4 matrix. I keep thinking
> there should be an easy way to do this using numpy, but I can't figure
> out the mojo to do it. Is that possible?

numpy questions are best asked (and best answered!) on the numpy list.

  http://www.scipy.org/Mailing_Lists

Now, you haven't given quite enough information for us to answer your question
definitively. What's the format of your array of points? Is it (N, 4) or (4, N)?
Is your (4, 4) matrix set up to left-multiply column-vectors or right-multiply
row-vectors?

I'm guessing that you have an (N, 4) array of N row-vectors and your (4, 4)
matrix  is set up to left-multiply column-vectors, as is the usual case. Since
you have row-vectors and your matrix needs column-vectors, you need to transpose
the matrix and multiply it on the *right* of your vectors array.

  dot(n_x_four, four_x_four.T)

If the matrix had already been set up to right-multiply row-vectors, then you
could skip the transpose.

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