[Numpy-discussion] Re: matrixmultiply problem

David M. Cooke cookedm at physics.mcmaster.ca
Thu Aug 12 13:32:03 CDT 2004


On Thu, Aug 12, 2004 at 04:05:41PM -0400, Alan G Isaac wrote:
> > The patch is in CVS now.
> 
> Can the conditions under which this problem occurs
> be simply stated?
> 
> Thank you,
> Alan Isaac

a = some matrix
b = some other matrix
transpose(b) is not contiguous

The numarray 1.0 (and earlier behaviour) is this:
dot(a,b) transposes b internally, finds it's not contiguous, and
makes a contiguous copy. Unfortunately, when it finishes, it
untransposes the *copy* of b back, not b itself.

So after dot(a, b), b is now the transpose of the original matrix

A quick fix is to define your own dot:
def dot(a, b):
    return numarray.dot(a, b.view())

The original b is then not touched, and the screwed-up matrix is
discarded. Note that transpose happens by fiddling with the layout of
the dimensions and strides in the array object; the data itself is not
touched.

[This all applies to matrixmultiply also, as matrixmultiply == dot]

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the Numpy-discussion mailing list