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
Cast iron has about how much carbon content?
Aliun [14]

Answer:

c

Explanation:

7 0
3 years ago
LUNES MARTES MIÉRCOLES JUEVES VIERNES SÁBADO DOMINGO
scZoUnD [109]

Answer:

si

Explanation:

8 0
3 years ago
A thick steel slab ( 7800 kg/m3 , c 480 J/kg K, k 50 W/m K) is initially at 300 C and is cooled by water jets impinging on one o
Nutka1998 [239]

Answer:

1791 secs  ≈ 29.85 minutes

Explanation:

( Initial temperature of slab )  T1 = 300° C

temperature of water ( Ts ) = 25°C

T2 ( final temp of slab ) = 50°C

distance between slab and water jet = 25 mm

<u>Determine how long it will take to reach T2</u>

First calculate the thermal diffusivity

∝  = 50 / ( 7800 * 480 ) = 1.34 * 10^-5 m^2/s

<u>next express Temp as a function of time </u>

T( 25 mm , t ) = 50°C

next calculate the time required for the slab to reach 50°C at a distance of 25mm

attached below is the remaining part of the detailed solution

5 0
3 years ago
An electric field is expressed in rectangular coordinates by E = 6x2ax + 6y ay +4az V/m.Find:a) VMN if point M and N are specifi
Fittoniya [83]

Answer:

a.) -147V

b.) -120V

c.) 51V

Explanation:

a.) Equation for potential difference is the integral of the electrical field from a to b for the voltage V_ba = V(b)-V(a).

b.) The problem becomes easier to solve if you draw out the circuit. Since potential at Q is 0, then Q is at ground. So voltage across V_MQ is the same as potential at V_M.

c.) Same process as part b. Draw out the circuit and you'll see that the potential a point V_N is the same as the voltage across V_NP added with the 2V from the other box.

Honestly, these things take practice to get used to. It's really hard to explain this.

3 0
3 years ago
Which tool ensures that a fastener has the proper amount of tightness
Sidana [21]

A torque wrench tool is a tool that ensures that a fastener has the proper amount of tightness.

<h3>What is the torque wrench used for?</h3>

The torque wrench tool is used to ensure screws and bolts are properly tightened. When performing home repairs and maintenance of equipment it is quite important that a torque wrench is used in other to prevent a scenario where a fastener (screws and bolts) does not become loose leading to equipment failure or damage. Because of its many advantages, this tool is often found in the possession of construction workers.

You can learn more about the benefits of a torque wrench tool here

brainly.com/question/15075481

#SPJ1

7 0
1 year ago
Other questions:
  • The car travels around the portion of a circular track having a radius of r = 500 ft such that when it is at point A it has a ve
    14·1 answer
  • What are the units or dimensions of the shear rate dv/dy (English units)? Then, what are the dimensions of the shear stress τ= μ
    14·1 answer
  • Given the circuit at the right in which the following values are used: R1 = 20 kΩ, R2 = 12 kΩ, C = 10 µ F, and ε = 25 V. You clo
    11·1 answer
  • A package is thrown down an incline at A with a velocity of 1 m/s. The package slides along the surface ABC to a conveyor belt w
    13·1 answer
  • (2 points) A perfectly mixed aeration pond with no recycle serves as the biological reactor for a small community. The pond rece
    15·1 answer
  • Explain the underlying physical reason why when we conduct various heat treatments on 1018 steel we expect the modulus of elasti
    8·1 answer
  • A force is a push or pull in? A.a circle B.an arc C.a straight line
    5·1 answer
  • What is the line called that has the red arrow pointing to it in the attached picture?
    6·1 answer
  • A system samples a sinusoid of frequency 230 Hz at a rate of 175 Hz and writes the sampled signal to its output without further
    9·1 answer
  • Two solid yellow center lines on a two-lane highway indicate:
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!