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
Accidents occur as a result of ____ and ____.
telo118 [61]

BRIGHT HEADLIGHTS

AND SEVERE WEATHER CONDITIONS

5 0
2 years ago
One kg of an idea gas is contained in one side of a well-insulated vessel at 800 kPa. The other side of the vessel is under vacu
laiz [17]

Answer:

Option C = internal energy stays the same.

Explanation:

The internal energy will remain the same or unchanged because this question has to do with a concept in physics or classical chemistry (in thermodynamics) known as Free expansion.

So, the internal energy will be equals to the multiplication of the change in temperature, the heat capacity (keeping volume constant) and the number of moles. And in free expansion the internal energy is ZERO/UNCHANGED.

Where, the internal energy, ∆U = 0 =quantity of heat, q - work,w.

The amount of heat,q = Work,w.

In the concept of free expansion the only thing that changes is the volume.

7 0
3 years ago
When we utilize a visualization on paper/screen, that visualization is limited to exploring: Group of answer choices Relationshi
Mila [183]

Answer:

As many variables as we can coherently communicate in 2 dimensions

Explanation:

Visualization is a descriptive analytical technique that enables people to see trends and dependencies of data with the aid of graphical information tools. Some of the examples of visualization techniques are pie charts, graphs, bar charts, maps, scatter plots, correlation matrices etc.

When we utilize a visualization on paper/screen, that visualization is limited to exploring as many variables as we can coherently communicate in 2-dimensions (2D).

6 0
3 years ago
A train travels 650 meters in 25 seconds. What is the train's velocity?
frosja888 [35]

The train is traveling 26 meters A second .

3 0
3 years ago
5. Assume that you and your best friend ench have $1000 to invest. You invest your money
Bezzdna [24]

Correct question reads;

Assume that you and your best friend each have $1000 to invest. You invest your money in a fund that pays 10% per year compound interest. Your friend invests her money at a bank that pays 10% per year simple interest. At the end of 1 year, the difference in the total amount for each of you is:

(a) You have $10 more than she does

(b) You have $100 more than she does

(c) You both have the same amount of money

(d) She has $10 more than you do

<u>Answer:</u>

<u>(d) She has $10 more than you do</u>

<u>Explanation</u>:

Using the compound interest formula

A= P [ (1-i)^n-1

Where P = Principal/invested amount, i = annual interest rate in percentage, and n = number of compounding periods.

<u>My compound interest is:</u>

= 1000 [ (1-0.1)^1-1

= $1000

$1,000 + $1,000 invested= $2,000 total amount received.

<u>My friend's simple interest is;</u>

To determine the total amount accrued we use the formula:

P(1 + rt) Where:

P = Invested Amount (1000)

I = Interest Amount (10,000)

r = Rate of Interest per year (10% or 0.2)

t = Time Period (1 )

= 1000 (1 + rt)

= 1000 (1 + 0.1x1)

= $1100 + $1000 invested = $2100 total amount received.

Therefore, we observe that she (my friend) has $100 more than I do.

5 0
3 years ago
Other questions:
  • for high-volume production runs, machining parts from solid material might not be the best choice of manufacturing operations be
    12·1 answer
  • Answer every question of this quiz
    7·1 answer
  • The heat flux through a 1-mm thick layer of skin is 1.05 x 104 W/m2. The temperature at the inside surface is 37°C and the tempe
    8·1 answer
  • The Emergency Stop Button icon on the Inputs toolbar can be used to press or release the Emergency Stop button on the CNC machin
    10·1 answer
  • In a diesel engine, the fuel is ignited by (a) spark (c) heat resulting from compressing air that is supplied for combustion (d)
    14·1 answer
  • A 2.5 m wide rough continuous foundation is placed in the ground at 1 m depth. There is bedrock present at 1 m depth below the b
    12·1 answer
  • 2.44mW of incident 520 nm light is directed through a1 cm sample cuvette and 0.68 mW of Plight exits the sample what is the abso
    9·1 answer
  • Name the famous engineer in the world​
    10·2 answers
  • A proposed embankment fill requires 7100 ft of compacted soil. The void ratio of the compacted fill is specified as 0.5. Four bo
    10·1 answer
  • Yeah this question might be difficult as most of the brainly community is math. Hope I can find at last one robotics person. ;-;
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!