Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

math_proof Group Title

modyfing the code to get n threads that compute each row, instead of row and column in python

  • one year ago
  • one year ago

  • This Question is Closed
  1. math_proof Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    import numpy import random import threading class MatrixMult(threading.Thread): """A thread which computes the i,j entry of A * B""" def __init__(self, A, B, i): super(MatrixMult, self).__init__() self.A = A self.B = B self.i = i #self.j = j def run(self): print "Computing %i, %i" % (self.i, self.i) x = 0 result=[] for k in range(self.A.shape[0]): x += self.A[self.i,k] * self.B[k,self.j] self.result=x print "Completed %i, %i" % (self.i, self.j) def mult(n): """A function to randomly create two n x n matrices and multiply them""" # Create two random matrices A = numpy.zeros((n,n)) B = numpy.zeros((n,n)) for i in range(n): for j in range(n): A[i,j] = random.randrange(0, 100) B[i,j] = random.randrange(0, 100) # Create and start the threads threads = [] for i in range(n): for j in range(n): t = MatrixMult(A, B, i) threads.append(t) t.start() for t in threads: t.join() C = numpy.zeros((n,n)) for t in threads: C[t.i,t.j] = t.result return C

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.