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]
2 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]2 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 engineer measures a sample of 1200 shafts out of a certain shipment. He finds the shafts have an average diameter of 2.45 inc
Vadim26 [7]

Answer: 78.89%

Explanation:

Given : Sample size : n=  1200

Sample mean : \overline{x}=2.45

Standard deviation : \sigma=0.07

We assume that it follows Gaussian distribution (Normal distribution).

Let x be a random variable that represents the shaft diameter.

Using formula, z=\dfrac{x-\mu}{\sigma}, the z-value corresponds to 2.39 will be :-

z=\dfrac{2.39-2.45}{0.07}\approx-0.86

z-value corresponds to 2.60 will be :-

z=\dfrac{2.60-2.45}{0.07}\approx2.14

Using the standard normal table for z, we have

P-value = P(-0.86

=P(z

Hence, the percentage of the diameter of the total shipment of shafts will fall between 2.39 inch and 2.60 inch = 78.89%

7 0
3 years ago
Give me top 5 British snacks
tia_tia [17]

Answer:

1. Mini Cheddars

2. Sausage Roll

3. Monster Munch

4. Cheese Twists

5. Flapjacks

6 0
2 years ago
Introduce JTA and JT
Vinil7 [7]
JT2 oaoaosnforeneomdocdmsnsksmsmsodnfnfj
7 0
2 years ago
What steps would you take to design an improved toothpaste container?
algol [13]

Answer:

A. Identify the need, recognize limitations of current toothpaste containers, and then brainstorm ideas on how to improve the existing

Explanation:

To design an improved toothpaste container, we must identify the needs of the customer, one of the major need is to make the container attractive to the sight. This is the first thing that will prompt a customer to wanting to buy the product (The reflectance/appearance).

Then recognize the limitation of the current design, what needed change. This will help in determining what is needed to be included and what should be removed based on identified customers need.

The last step is to brainstorm ideas on how to improve the existing designs. Get ideas from other colleagues because there is a saying that two heads are better than one. This will help in coming to a reasonable conclusion on the new design after taking careful consideration of people's opinion.

7 0
3 years ago
A large tank is filled to capacity with 500 gallons of pure water. Brine containing 2 pounds of salt per gallon is pumped into t
Nataly [62]

Answer:

A) A(t) = 10(100 - t) + c(100 - t)²

B) Tank will be empty after 100 minutes.

Explanation:

A) The differential equation of this problem is;

dA/dt = R_in - R_out

Where;

R_in is the rate at which salt enters

R_out is the rate at which salt exits

R_in = (concentration of salt in inflow) × (input rate of brine)

We are given;

Concentration of salt in inflow = 2 lb/gal

Input rate of brine = 5 gal/min

Thus;

R_in = 2 × 5 = 10 lb/min

Due to the fact that the solution is pumped out at a faster rate, thus it is reducing at the rate of (5 - 10)gal/min = -5 gal/min

So, after t minutes, there will be (500 - 5t) gallons in the tank

Therefore;

R_out = (concentration of salt in outflow) × (output rate of brine)

R_out = [A(t)/(500 - 5t)]lb/gal × 10 gal/min

R_out = 10A(t)/(500 - 5t) lb/min

So, we substitute the values of R_in and R_out into the Differential equation to get;

dA/dt = 10 - 10A(t)/(500 - 5t)

This simplifies to;

dA/dt = 10 - 2A(t)/(100 - t)

Rearranging, we have;

dA/dt + 2A(t)/(100 - t) = 10

This is a linear differential equation in standard form.

Thus, the integrating factor is;

e^(∫2/(100 - t)) = e^(In(100 - t)^(-2)) = 1/(100 - t)²

Now, let's multiply the differential equation by the integrating factor 1/(100 - t)².

We have;

So, we ;

(1/(100 - t)²)(dA/dt) + 2A(t)/(100 - t)³ = 10/(100 - t)²

Integrating this, we now have;

A(t)/(100 - t)² = ∫10/(100 - t)²

This gives;

A(t)/(100 - t)² = (10/(100 - t)) + c

Multiplying through by (100 - t)²,we have;

A(t) = 10(100 - t) + c(100 - t)²

B) At initial condition, A(0) = 0.

So,0 = 10(100 - 0) + c(100 - 0)²

1000 + 10000c = 0

10000c = -1000

c = -1000/10000

c = -0.1

Thus;

A(t) = 10(100 - t) + -0.1(100 - t)²

A(t) = 1000 - 10t - 0.1(10000 - 200t + t²)

A(t) = 1000 - 10t - 1000 + 20t - 0.1t²

A(t) = 10t - 0.1t²

Tank will be empty when A(t) = 0

So, 0 = 10t - 0.1t²

0.1t² = 10t

Divide both sides by 0.1t to give;

t = 10/0.1

t = 100 minutes

6 0
3 years ago
Other questions:
  • The emissivity of galvanized steel sheet, a common roofing material, is ε = 0.13 at temperatures around 300 K, while its absorpt
    7·1 answer
  • Which of the following vehicles has no emissions?
    9·1 answer
  • Discuss four (4) advantages of direct and indirect water supply system.
    5·2 answers
  • The following sentence can be categorized as what stage in the Scientific Method: Abraham notices that Saharan desert ants will
    6·1 answer
  • A force measuring instrument comes with a certificate of calibration that identifies two instrument errors and assigns each an u
    12·1 answer
  • Consider a machine of mass 70 kg mounted to ground through an isolation system of total stiffness 30,000 N/m, with a measured da
    9·1 answer
  • P9.28 A large vacuum tank, held at 60 kPa absolute, sucks sea- level standard air through a converging nozzle whose throat diame
    12·1 answer
  • A lightbulb has a fixed negative and positive connector. You cannot swap positive and negative sides of a lightbulb in a circuit
    9·2 answers
  • Suppose a manager of a certain mining company wants to determine the weekly food expenditure of the company’s employees. if ther
    7·1 answer
  • 10. What refrigerant is no longer manufactured in the<br> United States?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!