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 -- http://mail.python.org/mailman/listinfo/python-list