reset password
Author Message
vsevak
Posts: 18
Posted 05:07 Jan 16, 2016 |

3pts Create a method called "multiply" that takes a matrix and multiplies (dot product) this matrix against a matrix passed in and returns the result. If the shapes are incompatible, print "Shapes are incompatible" and return None.

I have doubt in above points that multiplies this matrix against a matrix passed in. 

Do we need to pass two matrix in constructor?

Can you please provide us sample input and sample output for this.

cs320stu66
Posts: 19
Posted 08:17 Jan 16, 2016 |

As of my understanding, for "2pts Create a constructor (__init__) that takes a Python list (1 or 2 dimensional) and stores in an instance variable the shape of the matrix (call it "shape", it should be a tuple) and an instance variable of the list that was passed in." we have to create a instance variable list which represents the matrixA. And lets assume that the matrix which you are passing it to multiply method is called matrixB ( def multiply(self, matrixB) ... ), then the return value of multiply method must be matrixA*matrixB ( dot product ) if the shape of both matrices are compatible.

Note: The instance variable matrixA must be set while creating instance of Matrix class.

msargent
Posts: 519
Posted 10:49 Jan 16, 2016 |

I won't do sample code for this, but each Matrix object keeps track of its own values. When you call the multiply method from a matrix, pass in another matrix, and use the values stored in the first matrix (they were passed in when you created it; your __init__ method takes a list as a parameter) object along with the matrix passed in to get the result. It's like Java's BigInteger.

Last edited by msargent at 10:51 Jan 16, 2016.
vsevak
Posts: 18
Posted 21:35 Jan 21, 2016 |

Can we use numpy or any other python modules?

Thanks.

msargent
Posts: 519
Posted 21:45 Jan 21, 2016 |

No. The point was to get you to figure out how the multiplications go. Using numpy makes it trivial.