[SciPy-user] Re: matrixmultiply and pxq times qxr matrices

Bob Minvielle baddlci at yahoo.com
Sun Sep 12 15:18:53 EDT 2004


Hello, I have what is probably a silly question, but I can not find
out the solution...

I am trying to multiply two matrices in python using the numarray
package
and it is not working. to be more concise, it is not working when I
do it
in a script, but it does work interactively... for example:

electron:~ number9$ python
Python 2.3 (#1, Sep 13 2003, 00:49:11) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> from numarray import *
>>> a = ([[0.5, 0.3, 0.6, 0.4],[0.5, 0.4, 0.6, 0.5]])
>>> b = ([0.9, 0.99, 0.98, 0.98])
>>> innerproduct(a,b)
array([ 1.727,  1.924])
>>> c = array([[0.5, 0.3, 0.6, 0.4],[0.5, 0.4, 0.6, 0.5]])
>>> d = array([0.9, 0.99, 0.98, 0.98])
>>> innerproduct(c,d)
array([ 1.727,  1.924])
>>> print c
[[ 0.5  0.3  0.6  0.4]
 [ 0.5  0.4  0.6  0.5]]
>>> print d
[ 0.9   0.99  0.98  0.98]


Ok, that looks great, but when I do this:

deltawtsL2 = rate * transpose(matrixmultiply(actoutsL1,
tderivsBenefL2))
Where a print actoutsL1 yeilds:
[[ 0.5         0.31002552  0.59868766  0.40131234]
 [ 0.5         0.40131234  0.59868766  0.5       ]]
and a print tderivBenefL2 yeilds:
[-0.54437211  0.44655051  0.43416131 -0.55163754]

I get an error:

Traceback (most recent call last):
  File "backprop.py", line 59, in ?
    deltawtsL2 = rate * transpose(matrixmultiply(actoutsL1,
tderivsBenefL2))
ValueError: innerproduct: last sequence dimensions must match.

I have printed out the values from within the script right before I
call
deltawtsL2 = <blah blah> and the values above are what it gives me.

I have (as noted above) tried this by hand and it works consistently.
Is the print statement not generating what is really in the array?
The arrays that I am trying to multiply come about from other
functions,
but the input to those functions are generated with the var =
array([....])
method.

Any suggestions as to where I should look now would be greatly
appreciated.

Thank you.




=====
Bob (number9)
baddlci at yahoo.com

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the SciPy-User mailing list