9

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.

8
  • numpy's matrix type does matrix multiplication, while the array type does pointwise multiplication, which do you want? Commented May 23, 2011 at 2:57
  • 1
    Is matrix multiplication like "dot product" when pointwise multiplcation is like every point multiply corresponding point? Commented May 23, 2011 at 3:03
  • Yes. Check it out in a console and see for yourself. If you could give me some example data and what result you expect I could tell you which operation you want. Commented May 23, 2011 at 3:04
  • I am doing image processing in python, a method called Pyramid Based Data Fusion Scheme. I have one question: Is there only one way to do addition of two matrix? Commented May 23, 2011 at 3:10
  • 5
    Numpy for Matlab Users (scipy.org/NumPy_for_Matlab_Users) has a nice summary of numpy ndarray and matrix operations. element-wise operations, broadcasting, matrix operations, etc. Commented May 23, 2011 at 5:03

1 Answer 1

14

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.