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
a vertical cylindrical container is being cooled in ambient air at 25 °C with no air circulation. if the initial temperature of
Sloan [31]

Answer:

the surface heat-transfer coefficient due to natural convection during the initial cooling period.  = 4.93 w/m²k

Explanation:

check attachement for answer explanation

7 0
3 years ago
Read 2 more answers
Discuss the difference between the observed and calculated values. Is this error? If yes, what is the source?
Scrat [10]

Answer and Explanation:

In any experiment, the observed values are the actual values obtained in any experiment.

The calculated values are the values that are measured by using the observed values in a formula.

The observed values are primary values whereas the calculated values are the secondary values as calaculations are made using observed values.

Yes, if the observed values are of low accuracy.

The values should be recorded with proper care and attention in order to avoid any error.

8 0
3 years ago
Engineering Careers Scavenger Hunt
emmasim [6.3K]

Answer:

c

Explanation:

it's the only engineering career

6 0
3 years ago
Read 2 more answers
Ruler game, HELPPPPP
viktelen [127]
D! :D
Hope I helped!!
3 0
2 years ago
Read 2 more answers
A vertical piston-cylinder device initially contains 0.2 m3 of air at 20°C. The mass of the piston is such that it maintains a c
Ann [662]

Answer:

Amount of air left in the cylinder=m_{2}=0.357 Kg

The amount of heat transfer=Q=0

Explanation:

Given

Initial pressure=P1=300 KPa

Initial volume=V1=0.2m^{3}

Initial temperature=T_{1}=20 C

Final Volume=V_{2}=0.1 m^{3}

Using gas equation

m_{1}=((P_{1}*V_{1})/(R*T_{1}))

m1==(300*0.2)/(.287*293)

m1=0.714 Kg

Similarly

m2=(P2*V2)/R*T2

m2=(300*0.1)/(0.287*293)

m2=0.357 Kg

Now calculate mass of air left,where me is the mass of air left.

me=m2-m1

me=0.715-0.357

mass of air left=me=0.357 Kg

To find heat transfer we need to apply energy balance equation.

Q=(m_{e}*h_{e})+(m_{2}*h_{2})-(m_{1}*h_{1})

Where me=m1-m2

And as the temperature remains constant,hence the enthalpy also remains constant.

h1=h2=he=h

Q=(me-(m1-m2))*h

me=m1-me

Thus heat transfer=Q=0

6 0
3 years ago
Other questions:
  • When using levers like scissors or hedge clippers, what can be done to increase the cutting force so that you don’t have to sque
    5·1 answer
  • A flat-plate solar collector is used to heat water by having water flow through tubes attached at the back of the thin solar abs
    8·1 answer
  • A hydraulic cylinder has a 125-mm diameter piston with hydraulic fluid inside the cylinder and an ambient pressure of 1 bar. Ass
    8·1 answer
  • What are the benefits of using a multi view sketch to communicate a design
    14·1 answer
  • Why would Chris most likely conclude that he should seek help? A. He feels in control of his emotions even though people annoy h
    15·2 answers
  • The natural material in a borrow pit has a mass unit weight of 110.0 pcf and a water content of 6%, and the specific gravity of
    11·1 answer
  • The heat transfer surface area of a fin is equal to the sum of all surfaces of the fin exposed to the surrounding medium, includ
    6·1 answer
  • TOPO NÀO CÓ CẤU HÌNH ĐA ĐIỂM
    15·2 answers
  • Global Convection Patterns include which of the following?
    12·1 answer
  • The resistance of a copper wire 200 m long is 21 Q. If its thickness (diameter) is 0.44 mm, its specific resistance is around___
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!