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
If a hoist lifts a 4500lb load 30ft in 15s, the power delivered to the load is a) 18.00hp b) 9000hp c) 16.36hp d) None of the ab
12345 [234]

Answer:

Explanation:

load = 4500lb                   lift height= 30 ft

time =15 s

velocity=\frac{30}{15} ft/s

velocity=2 ft/s

power = force\times velocity

power={4500}\times2

power= 9000 lb ft/s

1 hp= 550 lb ft/s

power= \frac{9000}{550} =16.36 hp

5 0
3 years ago
To compute the energy used by a motor, multiply the power that it draws by the time of operation. Con- sider a motor that draws
ehidna [41]

Answer:

E=52000Hp.h

E=38724920Wh

E=1.028x10^11 ftlb

Explanation:

To solve this problem you must multiply the engine power by the time factor expressed in h / year, to find this value you must perform the conventional unit conversion procedure.

Finally, when you have the result Hp h / year you convert it to Ftlb and Wh

E=(12.5hp)(\frac{16h}{day} )(\frac{5 days}{week} )(\frac{52week}{year} )\\

E=52000Hp.h

E=52000Hp.h(\frac{744.71Wh}{Hp.h} )\\

E=38724920Wh

E=52000Hph(\frac{1977378.4  ft lb}{1Hph}

E=1.028x10^11 ftlb

3 0
3 years ago
A fully braced structural member in a building is subjected to several different loads, including roof loads of D = 5 k and L_r
allochka39001 [22]

Answer: 37.4K

Explanation:

See attachment

7 0
3 years ago
ShoppingBay is an online auction service that requires several reports. Data for each auctioned item includes an ID number, item
daser333 [38]

Answer:

START

  READ ID_Number

  READ Item_description

  READ length_of_auction_Days

  READ minimum_required_bid  

  IF minimum_required_bid GREATER THAN 100

      THEN

          DISPLAY

              Item Details are

              Item Id : ID_Number

              Item Description: Item_description

              Length Action days: length_of_auction_Days

              Minimum Required Bid: minimum_required_bid

END

Explanation:

5 0
3 years ago
HAPPINESS DISCUSSION
RideAnS [48]

Answer:

uh because life sucks o_<

8 0
2 years ago
Read 2 more answers
Other questions:
  • Thermal energy generated by the electrical resistance of a 5-mm-diameter and 4-m-long bare cable is dissipated to the surroundin
    12·1 answer
  • Name two types of Transformers.
    6·1 answer
  • JAVA HADOOP MAPREDUCE
    13·1 answer
  • Matthew wants to manufacture a large quantity of products with standardized products having less variety. Which type of producti
    5·1 answer
  • Consider a Carnot refrigeration cycle executed in a closed system in the saturated liquid-vapor mixture region using 0.96 kg of
    11·1 answer
  • Emergency plans are being formulated so that rapid action can be taken in the event of an equipment failure. It is predicted tha
    12·2 answers
  • Dalton needs to prepare a close-out report for his project. Which part of the close-out report would describe
    6·1 answer
  • Draw a sinusoidal signal and illustrate how quantization and sampling is handled by
    8·1 answer
  • Plz help electrical technology
    15·2 answers
  • A 20cm-long rod with a diameter of 0.250 cm is loaded with a 5000 N weight. If the diameter of the bar is 0.490 at this load, de
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!