A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 2 years ago

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

  • This Question is Closed
  1. math_proof
    • 2 years ago
    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

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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.