Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding 2 matrix and Multiplying 2 matrix in python by using scipy/numpy

I am trying to use scipy and numpy to perform matrix addition and multiplication.

I have 2 matrix "a" and "b". my goal is to add "a" and "b" together and store the result into a matrix "c"

Also I want to multiply "a" and "b" and store into a matrix "d".

Are there any function perform like that in Scipy/Numpy?

Thanks a lot.

like image 481
Hold_My_Anger Avatar asked May 23 '11 02:05

Hold_My_Anger


1 Answers

Matrix multiplication:

a = numpy.matrix(a)
b = numpy.matrix(b)
c = a+b
d = a*b

Array multiplication (map operator.mul):

a = numpy.array(a)
b = numpy.array(b)
c = a+b
d = a*b
like image 179
sverre Avatar answered Oct 15 '22 14:10

sverre