1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
allsm [11]
3 years ago
5

Write a naive implementation (i.e. non-vectorized) of matrix multiplication, and then write an efficient implementation that uti

lizes Numpy's vectorization. When writing the function ensure that the matrix dimensions are correct (print the message Wrong dimensions! otherwise).

Engineering
1 answer:
erik [133]3 years ago
7 0

Answer:

import numpy as np  

import time  

def matrixMul(m1,m2):      

   if m1.shape[1] == m2.shape[0]:  

       

       t1 = time.time()

       r1 = np.zeros((m1.shape[0],m2.shape[1]))

       for i in range(m1.shape[0]):

           for j in range(m2.shape[1]):

               r1[i,j] = (m1[i]*m2.transpose()[j]).sum()

       t2 = time.time()

       print("Native implementation: ",r1)

       print("Time: ",t2-t1)

       

       t1 = time.time()

       r2 = m1.dot(m2)

       t2 = time.time()

       print("\nEfficient implementation: ",r2)

       print("Time: ",t2-t1)

       

   else:

       print("Wrong dimensions!")

Explanation:

We define a function (matrixMul) that receive two arrays representing the two matrices to be multiplied, then we verify is the dimensions are appropriated for matrix multiplication if so we proceed with the native implementation consisting of two for-loops and prints the result of the operation and the execution time, then we proceed with the efficient implementation using .dot method then we return the result with the operation time. As you can see from the image the execution time is appreciable just for large matrices, in such a case the execution time of the efficient implementation can be 1000 times faster than the native implementation.

You might be interested in
What is protection scheme?
serg [7]

Answer:

The objective of a protection scheme is to keep the power system stable by isolating only the components that are under fault, whilst leaving as much of the network as possible still in operation.

Explanation:

The devices that are used to protect the power systems from faults are called protection devices.

5 0
3 years ago
How do I draw this from the side?
tangare [24]

Answer:

draw it 3D

Explanation:

because it's a 3D picture

6 0
3 years ago
Polymers can be natural or synthetic. a)-True b)- false?
Olenka [21]

Answer:

TRUE

Explanation:

Polymers can be natural as well as synthetic

The polymer which are found in nature are called natural polymer tease polymer are not synthesized, they are found in nature

Example of natural polymers is cellulose, proteins etc

On the other hand synthetic polymers are not found in nature they are synthesized in market

There are many example of synthetic polymer

Example : nylon, Teflon etc  

So it is a true statement

8 0
4 years ago
What is the critical path and time duration?
kvasek [131]

The critical path is A-B-C, with a duration of 15 minutes.

<u>Explanation</u>:

  • The critical path is A-B-C, with a term of 15 minutes. You don't need to be knowledgeable in computer lingo to make sense of this one (as I made sense of it absent a lot of data on that half of the condition). Here's the manner by which I made sense of this.  
  • The main thing I saw was that "predecessor" was utilized, which implies something precedes the other thing. That provided me the primary insight that A precedes B and C, and that B must precede C. Then, I just included the term times for the three ways, which allowed me 15 minutes.
3 0
3 years ago
(a) A 10.0-mm-diameter Brinell hardness indenter produced an indentation 2.3 mm in diameter in a steel alloy when a load of 1000
vampirchik [111]

Answer:

(a)  We are asked to compute the Brinell hardness for the given indentation. for HB, where P= 1000 kg, d= 2.3 mm, and D= 10 mm.  

Thus, the Brinell hardness is computed as

HB=2P/\pi D{D-\sqrt{D^2-d^2}

=2*1000hg/\pi (10mm)[10mm-\sqrt{(1000^2-(2.3mm)^2} ]

(b)    This  part  of  the  problem  calls  for  us  to  determine  the  indentation diameter d which  will  yield  a  270  HB  when P=  500  kg.  

d=\sqrt{D^2-[D-\frac{2P}{(HB)\pi D} } ]^2\\=\sqrt{(10mm)^2-[10mm-\frac{2*500}{450( \pi10mm)} } ]^2

6 0
4 years ago
Other questions:
  • For the speed equation along centerline of a diffuser, calculate the fluid acceleration along the diffuser centerline as a funct
    5·2 answers
  • What is the weight of a glider with a mass of 5.3 grams? (Hint: watch your units!)
    12·1 answer
  • A _________ is a PLD featuring a general structure that allows very high logic capacity and offers more narrow logic resources a
    5·1 answer
  • Technician A says independent shops are not affiliated with vehicle manufacturers, but it is easy for technicians who work in th
    8·1 answer
  • In using the drag coefficient care needs to be taken to use the correct area when determining the drag force. What is a typical
    7·1 answer
  • Which of the following is not a step in a building’s life cycle?
    6·1 answer
  • A battery provides electricity in the state of ?
    15·1 answer
  • Technicians are normally paid in all of the following methods except:
    8·2 answers
  • I need your help to answer in the picture plss help me!​
    15·1 answer
  • It’s busy at the bakery counter , and a loyal customer / member stops you to charge as he talking , you notice another customer
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!