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
An array of electronic chips is mounted within a sealedrectangular enclosure, and colling is implemented by attaching analuminum
Licemer1 [7]

Answer:

Base temperature is 46.23 °C

Explanation:

I've attached explanations

6 0
3 years ago
In order to fill a tank of 1000 liter volume to a pressure of 10 atm at 298K, an 11.5Kg of the gas is required. How many moles o
lesya [120]

Answer:

The molecular weight will be "28.12 g/mol".

Explanation:

The given values are:

Pressure,

P = 10 atm

  = 10\times 101325 \ Pa

  = 1013250 \ Pa

Temperature,

T = 298 K

Mass,

m = 11.5 Kg

Volume,

V = 1000 r

   = 1 \ m^3

R = 8.3145 J/mol K

Now,

By using the ideal gas law, we get

⇒ PV=nRT

o,

⇒ n=\frac{PV}{RT}

By substituting the values, we get

       =\frac{1013250\times 1}{8.3145\times 298}

       =408.94 \ moles

As we know,

⇒ Moles(n)=\frac{Mass(m)}{Molecular \ weight(MW)}

or,

⇒        MW=\frac{m}{n}

                   =\frac{11.5}{408.94}

                   =0.02812 \ Kg/mol

                   =28.12 \ g/mol

3 0
3 years ago
A vertical cylinder (Fig. P3.227) has a 61.18-kg piston locked with a pin, trapping 10 L of R-410a at 10◦C with 90% quality insi
Whitepunk [10]

Hey! How are you? My name is Maria, 19 years old. Yesterday broke up with a guy, looking for casual sex.

Write me here and I will give you my phone number - *pofsex.com*

My nickname - Lovely

4 0
3 years ago
Joe Bruin has a big lawn in front of his house that is 30 meters wide and 20 meters long. Josephine makes him go out and mow the
zysi [14]

<u>Explanation:</u>

5 Horsepower for 30 mins,

(5)(745.7) = 3.7285 KW power delivered

General Efficiency of IC engine = 20%

Power required = \frac{3 \cdot 7285}{0 \cdot 2}=18 \cdot 6425 kw

Energy required per week,

=P × Time = 18.64 × 60 × 30 = 33.5565 MJ

Lawn area = (30) (20) = 600m^{2}

let sunlight hours be 8 hours

Hence, solar power input on lawn,

=5.62×3600 = 20232 kJ/m^{2}/day

energy input in lawn = (600) (20232) (7)

                                  = 84974.4 mJ/week

Chemical efficiency by photosynthesis = 4%

Chemical content in grass = (84974.4) (0.04)

                                            = 3398.97 mJ

Mass of the clippers  \(=(30)(20)(1 \cdot 096)^{2}(667)\)

                                  \(=478632 \cdot 33\) pounds

Removing water content,

dried grass clippings \(=95726.46\) pound

                                    = 11533.25 gallons

Trash cans repaired  

                                     =\frac{11533}{50} =230.66\\=231 cans

By burning the gas, total energy input = 3398.97 MJ × 0.2

                                                                = 679.794 MJ

Efficiency of steeling engine  =  20%

Energy output by engine = 679.794 ×0.2

                                          = 135.96 mJ

Energy required by mover = 33.5565 mJ

Hence, Energy (output) ⇒ energy required

5 0
3 years ago
Engineers create a new metal that is stronger than steel but much lighter. This material is also significantly cheaper than what
zysi [14]

The best step for the engineers to make next is option D. Begin to design an airplane using this metal.

<h3>What is the metallic is plane parts?</h3>

Aluminum and its alloys are nevertheless very famous uncooked substances for the production of business planes, because of their excessive electricity at exceedingly low density. Currently, excessive-electricity alloy 7075, which includes copper, magnesium and zinc, is the only used predominantly withinside the plane industry.

The solution is D, due to the fact even as it's far crucial to marketplace the fabric and ensure humans are inquisitive about buying, they first want to attempt to layout aircraft the usage of this fabric. There isn't anyt any use promoting an aircraft constituted of this material_ if a aircraft can not be built.

Read more about the aircraft:

brainly.com/question/5055463

#SPJ1

7 0
2 years ago
Other questions:
  • How can endurance athletes best delay muscle fatigue during training? a. By avoiding sports drinks during exercise b. By eating
    6·2 answers
  • 5.5 A scraper with a 275 hp diesel engine will be used to excavate and haul earth for a highway project. An evaluation of the jo
    10·1 answer
  • Sketch the velocity profile for laminar and turbulent flow.
    15·1 answer
  • While discussing run-flat tires: Technician A says that some are self-sealing tires and are designed to quickly and permanently
    15·1 answer
  • The advantages of solar cells include all of the following, except a.moderate net energy yield b.little or no direct emissions o
    11·1 answer
  • Determine the output torque To????????p????????, the speed reduction ratio of the transmission R, the tangential loads imposed o
    13·2 answers
  • When we utilize a visualization on paper/screen, that visualization is limited to exploring: Group of answer choices Relationshi
    9·1 answer
  • Air,in a piston cylinder assembly, is initially at 300 K and 200 kPa.It is then heated at constant pressure to 600 K. Determine
    12·2 answers
  • Please help been stuck on this for a couple minutes
    5·1 answer
  • All of these are true about steel EXCEPT that:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!