Newbie question about numpy
Avell Diroll
avelldiroll at yahoo.fr
Thu Aug 24 12:16:04 EDT 2006
Paul Johnston wrote:
(snip)
> I noted the lack of matrices so installed numpy
(snip)
> _________________________________________________________
> from numpy import *
>
> a = array([[1,2,3],[4,5,6],[1,2,3]])
> b = array([[1,3,6],[2,5,1],[1,1,1]])
(snip)
> print "a * b is \n", a * b
> _________________________________________________________
(snip)
> a * b is
> [[ 1 6 18]
> [ 8 25 6]
> [ 1 2 3]]
> _________________________________________________________
>
>
> I know its a long time since my degree but that's not matrix
> multiplication is it ?
You consider that a and b are matrices, but for the python interpreter
they are arrays so a*b returns the multiplication of 2 arrays.
For matrices multiplication, you could get a hint by typing the
following in the interpreter :
>>> import numpy
>>> dir(numpy)
>>> help(numpy.matrixmultiply) #type "q" to exit
which could make you want to try the following code :
>>> from numpy import *
>>> a = array([[1,2,3],[4,5,6],[1,2,3]])
>>> b = array([[1,3,6],[2,5,1],[1,1,1]])
>>> print matrixmultiply(a,b)
...
output :
...
array([[ 8, 16, 11],
[20, 43, 35],
[ 8, 16, 11]])
...
HIH,
avell
More information about the Python-list
mailing list