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
15 POINTS! Help.
IRISSAK [1]

Answer: it would  overload

Explanation:

4 0
3 years ago
Read 2 more answers
The annual inventory cost C for a manufacturer is given below, where Q is the order size when the inventory is replenished. Find
Nataly_w [17]

The change in annual cost when Q is increased from 340 to 341 is -1.23 and the instantaneous rate of change when Q = 340 is -1.25

<h3>How to find the Instantaneous rate of change?</h3>

The annual inventory cost C for a manufacturer is given as;

C = (1012000/Q) + 7.5Q

where Q is the order size when the inventory is replenished.

Now, the change in C can be calculated by evaluating the cost function at Q = 340 and Q = 341

Change in C = [1,012,000/341 + 7.5*341] - [1,012,000/340 + 7.5*340] ≈ -1.23

Instantaneous rate of change in C is first order derivative C':

C'(Q) = -1,012,000/(Q²) + 7.5

C'(340) = -1,012,000/(340²) + 7.5 ≈ -1.25

Read more about Instantaneous rate of change at; brainly.com/question/14666106

#SPJ1

8 0
2 years ago
Aaron needs to create a building design for a restaurant with colors that depict excitement and vibrancy. Which color can Aaron
zloy xaker [14]

Answer:

I'm no engineer, but blue and purple are cool colors and white is every color so I'd go with orange

7 0
3 years ago
Read 2 more answers
Think about how could you design, build, and test a light maze. What specific behavior of light will be essential to the success
Mrac [35]

Answer:

Reflection

Explanation:

The specific behavior of light that will be essential to ensure the success of your design is "Reflection". This is because light maze makes use of a mirror and it's the light that is reflected that we see with our eyes. Also, the manner in which light is reflected off objects will affect the colors that are reflected as well.

4 0
3 years ago
Which of the following has led to a safer and more prosperous global community within the last century? the Bronze Age composite
sattari [20]

Answer:

The bronze age

4 0
4 years ago
Read 2 more answers
Other questions:
  • To operate a vehicle in Florida, you must
    10·2 answers
  • What is the maximum number of 12-2 with ground nonmetallic-sheathed cables permitted in an 18-cubic-inch device box if two singl
    11·2 answers
  • When watching your weight, you want to snack smart. To do that, you want a snack that is going to __________.
    13·1 answer
  • A refrigerator has a cooling load of 50 kW. It has a COP of 2. It is run by a heat engine which consumes 50 kW of heat to supply
    12·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    10·1 answer
  • Describe with an example how corroded structures can lead to environment pollution? ​
    13·1 answer
  • The temperature controller for a clothes dryer consists of a bimetallic switch mounted on an electrical heater attached to a wal
    12·1 answer
  • Select the correct answer. Jude is a mechanical engineer. He works in the automobile industry. He is creating a prototype of an
    13·1 answer
  • Using your knowledge of how an ATM is used, develop a set of use cases that could serve as a basis for understanding the require
    15·1 answer
  • Lynx eat snowshoe hares, and snowshoes hears eat plants. Which term can be applied to the lynx in this food chain example? Prima
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!