Is numarray matrixmultiply supposed to transpose the second argument?

R

Raoul

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

Christopher T King

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

Raoul Meuldijk

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

Christopher T King

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

Raoul Meuldijk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top