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 simple Brayton cycle using air as the working fluid has a pressure ratio of 10.9. The minimum and maximum temperatures in the
ladessa [460]

Air pressure at the end of the Turbine exit is : 730.57 K

<u>Given data :</u>

Pressure ratio ( p₂ / p₁ )= 10.9

minimum temperature ( T₁ ) = 280 K

maximum temperature ( T₃ ) = 1410 K

Assuming :

constant specific heat and efficiency of 100%

<h3 /><h3>Determine the Air pressure at the end of the turbine exit </h3>

For air :

Cp = 1.005 kJ/kg.k,  Cv = 0.718 kJ/kg.k,  v = 1.4

Given that efficiency for compressor and turbine is 100% the process ( 1-2 , 3 - 4 ) will all be isentropic

We will Apply the formula below

\frac{T_{2} }{T_{1} } = ( \frac{p_{2} }{p_{1} } )^{\frac{v-1}{v} } = ( \frac{V_{1} }{V_{2} } )^{v-1}

Insert values into equation ( 1 )

T₂ = 551.147 K  ( temperature at compressor exit )

<u />

<u>Next : Determine the </u><u>value </u><u>of the temperature at </u><u>Turbine exit </u><u>( T₄ )</u>

T₃ / T₄ = 10.7^^{\frac{1.4-1}{1.4} }

Therefore : T₄ = 1410 / 10.7^0.286

                        = 1410 / 1.93

                        = 730.57 K

Hence we can conclude that the Air pressure at the end of the Turbine exit is :  730.57 K .

Learn more about Turbine : brainly.com/question/894340

6 0
2 years ago
Write an ALP to separate odd and even numbers from an array of N numbers; arrange odd
Marta_Voda [28]

Below is the program to separate odd and even numbers                                  

<u>Explanation</u>:

<u>L1:</u>

         mov ah,00

         mov al,[BX]

         mov dl,al

         div dh

         cmp ah,00

         je EVEN1

         mov [DI],dl

         add OddAdd,dl

         INC DI

         INC BX

         Loop L1

         jmp CAL

    <u>EVEN1:</u>

         mov [SI],dl

         add Even Add,dl

         INC SI

         INC BX

         Loop L1

    <u>CAL:   </u>  

         mov ax,0000

         mov bx,0000

         mov al,OddAdd

         mov bl,EvenAdd

         MOV  ax,4C00h

         int 21h

end

The above program separates odd and even numbers from the array using 8086 microprocessor. It has odd numbers in 2000h and even numbers in 3000h.

6 0
4 years ago
Calculate the current in the 8-W resistor of Figure below by using Thevenin’s theorem. What will be its value of connections of
kvv77 [185]

solution from c hegg. hope it helps. see photos explanation

7 0
4 years ago
The viscosity of the water was 2.3×10^−5lb⋅⋅s/ft^2 and the water density was 1.94 slugs/ft^3. Estimate the drag on an 88-ft diam
Lina20 [59]

Answer:

hello your question is incomplete attached below is the complete question

answer : Drag force = 1.3 Ib

Explanation:

we have to represent the dimensions of the drag force in terms of FLT

i.e : D = f( <em>d,v,p,u </em>) represented in terms of FLT

D = F , V = LT^-1,  d = L, p = FL^-4 T^2

u = FL^-2 T,  Number of independent terms = 5

attached below is the detailed solution

6 0
4 years ago
In a manufacturing process, long aluminum rods of square cross section with d = 25 mm are cooled from an initial temperature of
laiz [17]

Answer:

The time required will be 511 seconds.

6 0
3 years ago
Read 2 more answers
Other questions:
  • 1. A vertical curve joins a -1.2% grade to a +0.8% grade. The two grades intersect at station 75 + 00 and elevation 50.90 m abov
    8·1 answer
  • Give an example of a model code.
    5·1 answer
  • The natural water content of a Boston Blue Clay soil sample was found to be 14.6% through oven drying. It has been calculated th
    8·1 answer
  • The rolling process is governed by the frictional force between the rollers and the workpiece. The frictional force at the entra
    5·1 answer
  • A heat engines is operating on a Carnot cycle and has a thermal efficiency of 55 percent. The waste heat from this engine is rej
    10·1 answer
  • How does your physical location impact the design of your product?
    15·1 answer
  • What truck you like the best
    9·2 answers
  • Nbel2, i dont know where you've been all this time but i hope you arent missing please respond i haves heard from you since may
    8·2 answers
  • Which of the following statements are true.
    14·1 answer
  • Can anyone explain how a Halbek Device works
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!