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 student lives in an apartment with a floor area of 60 m2 and ceiling height of 1.8 m. The apartment has a fresh (outdoor) air
USPshnik [31]

Answer:

4

Explanation:

5 0
3 years ago
To become familiar with the general equations of plane strain used for determining in-plane principal strain, maximum in-plane s
lukranit [14]

Answer:

a) -1.46 x 10∧-5, 1.445x 10∧-4, -6.355 x 10∧-4

b) 3.926 x 10∧-4, -2.626 x 10∧-4

c) 6.552 x 10∧-4, 6.5 x 10∧-5

Explanation:

a) -1.46 x 10∧-5, 1.445x 10∧-4, -6.355 x 10∧-4

b) 3.926 x 10∧-4, -2.626 x 10∧-4

c) 6.552 x 10∧-4, 6.5 x 10∧-5

The explanation is shown in the attachment. I hope i have been able to help.

3 0
3 years ago
A surveyor knows an elevation at Catch Basin to be elev=2156.77 ft. The surveyor takes a BS=2.67 ft on a rod at BM Catch Basin a
fenix001 [56]

Answer:

the elevation at point X is 2152.72 ft

Explanation:

given data

elev = 2156.77 ft

BS = 2.67 ft

FS = 6.72 ft

solution

first we get here height of instrument that is

H.I = elev + BS   ..............1

put here value

H.I =  2156.77 ft + 2.67 ft  

H.I = 2159.44 ft

and

Elevation at point (x) will be

point (x)  = H.I - FS   .............2

point (x)  = 2159.44 ft  - 6.72 ft

point (x)  = 2152.72 ft

3 0
3 years ago
Write a function named "read_prices" that takes one parameter that is a list of ticker symbols that your company owns in their p
ohaa [14]

Answer:

import pandas pd

def read_prices(tickers):

price_dict = {}

# Read ingthe ticker data for all the tickers

for ticker in tickers:

# Read data for one ticker using pandas.read_csv  

# We assume no column names in csv file

ticker_data = pd.read_csv("./" + ticker + ".csv", names=['date', 'price', 'volume'])

# ticker_data is now a panda data frame

# Creating dictionary

# for the ticker

price_dict[ticker] = {}

for i in range(len(ticker_data)):

# Use pandas.iloc  to access data

date = ticker_data.iloc[i]['date']

price = ticker_data.iloc[i]['price']

price_dict[ticker][date] = price

return price_dict  

7 0
4 years ago
The homogeneous, reversible, exothermic, liquid phase reaction: A근R Is being carried out in a reactor system consisting of an id
baherus [9]

Answer:

attached below

Explanation:

3 0
3 years ago
Other questions:
  • The popularity of orange juice, especially as a breakfast drink, makes it an important factor in the economy of orange-growing r
    14·1 answer
  • Using Von Karman momentum integral equation, find the boundary layer thickness, the displacement thickness, the momentum thickne
    14·1 answer
  • What do you think are the advantages and disadvantages of isothermal constant volume high extension cycle? And how efficient do
    13·1 answer
  • Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is pai
    11·1 answer
  • Some General Motors flex fuel vehicles do not use a fuel sensor to measure the percentage of ethanol in the fuel. These vehicles
    5·1 answer
  • I will put other link in comments
    12·1 answer
  • 8. What is the density of an object with a mass of 290.5 g and volume of 83 cm 3?​
    13·1 answer
  • Is there anyone who can help me with welding?
    7·1 answer
  • Subject : SCIENCE
    12·1 answer
  • Which of the following is most likely to require changes to existing zoning laws?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!