Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is numarray matrixmultiply supposed to transpose the second argument?

Reply
Thread Tools

Is numarray matrixmultiply supposed to transpose the second argument?

 
 
Raoul
Guest
Posts: n/a
 
      07-19-2004
It appears that matrixmultiply(A,B) has a side-effect of transposing the
second argument (B).
Is this supposed to happen?
Is there anyway to prevent it from transposing?

This shows what happens:


#! /usr/bin/env python
from numarray import *

A=array([[350],
[370],
[510],
[490],
[500]])

B=array([[35,37,51,49,50]])

print "A and B before matmul:"
print A
print B

AB=matrixmultiply(A,B)

print "AxB, A, B, after matmul:"
print AB
print A
print B

print"Apparantly, the second argument of matrixmultiply(A,B) is always
transposed."
------------ And now a word from our sponsor ----------------------
For a quality mail server, try SurgeMail, easy to install,
fast, efficient and reliable. Run a million users on a standard
PC running NT or Unix without running out of power, use the best!
---- See http://netwinsite.com/sponsor/sponsor_surgemail.htm ----
 
Reply With Quote
 
 
 
 
Christopher T King
Guest
Posts: n/a
 
      07-19-2004
On Mon, 19 Jul 2004, Raoul wrote:

> A=array([[350],
> [370],
> [510],
> [490],
> [500]])
>
> B=array([[35,37,51,49,50]])
>
> print "A and B before matmul:"
> print A
> print B
>
> AB=matrixmultiply(A,B)
>
> print "AxB, A, B, after matmul:"
> print AB
> print A
> print B


This works for me (B before == B after). Which version of numarray are
you using?

 
Reply With Quote
 
 
 
 
Raoul Meuldijk
Guest
Posts: n/a
 
      07-19-2004

>
> This works for me (B before == B after). Which version of numarray are
> you using?
>


It's version 1.0, on Python 2.3+.
I do have one lengthy example where the second argument was not changed
(on one matmul, all the others in that example did transpose), but was
not able to reproduce that in a small example; so it seems not to be
consistent.

For completeness, here's my output, as you can see the row-vector B has
changed into a column-vector.

A and B before matmul:
[[350]
[370]
[510]
[490]
[500]]
[[35 37 51 49 50]]
AxB, A, B, after matmul:
[[12250 12950 17850 17150 17500]
[12950 13690 18870 18130 18500]
[17850 18870 26010 24990 25500]
[17150 18130 24990 24010 24500]
[17500 18500 25500 24500 25000]]
[[350]
[370]
[510]
[490]
[500]]
[[35]
[37]
[51]
[49]
[50]]
Apparantly, the second argument of matrixmultiply(A,B) is always transposed.
 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      07-19-2004
Raoul wrote:
> It appears that matrixmultiply(A,B) has a side-effect of transposing the
> second argument (B).


I can verify this on Mac OSX with the latest CVS of numarray. Please
post a bug report to the tracker.

http://sourceforge.net/tracker/?atid...69&func=browse

--
Robert Kern


"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
Reply With Quote
 
Christopher T King
Guest
Posts: n/a
 
      07-19-2004
On Mon, 19 Jul 2004, Raoul Meuldijk wrote:

> > This works for me (B before == B after). Which version of numarray are
> > you using?

>
> It's version 1.0, on Python 2.3+.
> I do have one lengthy example where the second argument was not changed
> (on one matmul, all the others in that example did transpose), but was
> not able to reproduce that in a small example; so it seems not to be
> consistent.


Okay, I was using 0.9. Upgrading to 1.0 confirms the error. This is a
bug in numarray, but it has already been fixed in CVS. As a temporary
fix, use the original Python definition (ripped from numarraycore.py):

def dot(array1, array2):
return ufunc.innerproduct(array1, swapaxes(array2, -1, -2))

matrixmultiply = dot

This will fix both matrixmultiply and dot, as they are both affected by
the bug.

 
Reply With Quote
 
Raoul Meuldijk
Guest
Posts: n/a
 
      07-20-2004
Robert Kern wrote:
> Raoul wrote:
>
>> It appears that matrixmultiply(A,B) has a side-effect of transposing the
>> second argument (B).

>
>
> I can verify this on Mac OSX with the latest CVS of numarray. Please
> post a bug report to the tracker.
>
> http://sourceforge.net/tracker/?atid...69&func=browse


I have reported it, thanks.
 
Reply With Quote
 
Raoul Meuldijk
Guest
Posts: n/a
 
      07-20-2004

> Okay, I was using 0.9. Upgrading to 1.0 confirms the error. This is a
> bug in numarray, but it has already been fixed in CVS. As a temporary
> fix, use the original Python definition (ripped from numarraycore.py):
>
> def dot(array1, array2):
> return ufunc.innerproduct(array1, swapaxes(array2, -1, -2))
>
> matrixmultiply = dot
>
> This will fix both matrixmultiply and dot, as they are both affected by
> the bug.
>

Your fix works perfectly! Thanks!

Raoul
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transpose in java nk Java 5 09-02-2006 11:31 PM
Help needed with Transpose XML and XSLT problem infiniti XML 4 01-16-2006 01:28 PM
What is the slickest way to transpose a square list of lists (tuple oftuples)? Gerard Brunick Python 3 01-09-2006 08:09 PM
Graph - node - transpose VisionSet Java 4 10-18-2005 07:15 PM
Export datagrid to Excel template, transpose ? sweeney_jones@hotmail.com ASP .Net 0 08-18-2005 09:15 PM



Advertisments