470,614 Members | 1,396 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Is numarray matrixmultiply supposed to transpose the second argument?

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 ----
Jul 18 '05 #1
6 1881
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?

Jul 18 '05 #2

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.
Jul 18 '05 #3
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
rk***@ucsd.edu

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Jul 18 '05 #4
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.

Jul 18 '05 #5
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.
Jul 18 '05 #6
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
Jul 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Eugene Druker | last post: by
2 posts views Thread by Marc Schellens | last post: by
11 posts views Thread by grv | last post: by
6 posts views Thread by Michael Drumheller | last post: by
5 posts views Thread by Peter Dobcsanyi | last post: by
5 posts views Thread by George Sakkis | last post: by
3 posts views Thread by Colin J. Williams | last post: by
reply views Thread by andrewfelch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.