[Tutor] Matrix Multiplication user entries
Mats Wichmann
mats at wichmann.us
Fri Mar 23 15:16:29 EDT 2018
On 03/23/2018 12:02 AM, Noor Alghanem wrote:
> Hello,
>
> I am trying to write a program that is basically multiplying two matrices
> one of size 1x8 and the other one of size 8x4. The different thing that I
> am trying to figure out is that I want the program to ask the user to enter
> the values for the 1x8 matrix only which will be used in the multiplication
> process. How do I do that, please provide an example as I wasn't able to
> find one online that works. Also, if you can please include an example of
> matrix multiplication that is similar in idea to what I am trying to write.
For asking questions here, we really like if you show something you've
tried, so we can point out where it can be improved.
Some hints: for the second part, assuming I get what you want, you have
to change the shape of one matrix so you can multiply. So if your one
matrix will be a and the other b, something like:
import numpy
a = numpy.array(... initialization of 8x4 matrix ...)
b = numpy.array(... initialization of 1x8 matrix ...)
b.resize(a.shape) #
print a * b
# or, depending on what you want (check the documentation - one form
# zero-extends, the other duplicates):
b = numpy.resize(b, a.shape)
print a * b
print things out along the way if you're not sure what they're doing
does this help? (it's trickier if you want to avoid numpy! - I can't
tell if this is homework that has some specific requirements on what you
can and cannot use)
More information about the Tutor
mailing list