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
NeX [460]
3 years ago
8

In this this problem you will be using for loops to take a matrix of random number and create a new matrix that is the same as t

he random matrix, but with zeros on the diagonal. a) Create matrix m that is a 10x10 matrix of random whole numbers from 1 to 20. You will have to manipulate the random number generator function to modify the interval and get only whole numbers. b) Create a for loop that runs for index i equal to the index for every row in the matrix. Next, create a nested for loop that runs for index j equal to the index for every column in the matrix. This is very similar to the Your Turn - Extra slide of Lecture 13. c) Now, we want to use our for loops to create a new niatrix, n, that is equal to matrix m, but with zeros on the diagonal. You should use an if/else statement to create this new matrix. If the location is on the diagonal (i=j), then the value of matrix n at the location will be zero. Otherwise, the value of matrix n equals the value of matrix m at each location
Engineering
1 answer:
motikmotik3 years ago
5 0

Answer:

import numpy as np

# creating matrix of order 10*10 with random numbers between 1 and 20

m = np.random.randint(1,20, size=(10,10))

# create new matrix which reads matrix m and produces zero along the diagonal

n = np.random.randint(1,20, size=(10,10)) # create new matrix, n

for i in range(0,10): # loop through row of matrix

 for j in range(0,10): # loop through column of the matrix

   if i==j: # check for the diagonal element

     n[i][j] = 0 # asign diagonal value to zero

   else:

     n[i][j] = m[i][j] # assign the value of matrix m to n

# displaying m and n matrix in the given format using disp function

from io import StringIO

buf = StringIO()

np.disp(m,device=buf)

m = buf.getvalue()

m = m[1:-1] #removing the extra [ and ]from beginning and end

print("m = ")

print(m.replace(" [","").replace('[',"").replace(']',""))

buf = StringIO()

np.disp(n,device=buf)

n = buf.getvalue()

n = n[1:-1] #removing the extra [ and ]from beginning and end

print("n = ")

print(n.replace(" [","").replace('[',"").replace(']',""))

Explanation:

You might be interested in
A 200 W vacuum cleaner is powered by an electric motor whose efficiency is 70%. (Note that the electric motor delivers 200 W of
Goshia [24]

Answer:

The rate at which this vacuum cleaner supply energy to the room when running is 285.71 Watts.

Explanation:

power efficiency of electric motor = 70% = 0.70

The power output of the vacuum cleaner =P_o= 200 W

The power output of the vacuum cleaner = P_i

Efficiency=\frac{P_o}{P_i}

0.70=\frac{200 W}{P_i}

P_i=\frac{200 W}{0.70}=285.71 W

The rate at which this vacuum cleaner supply energy to the room when running is 285.71 Watts.

5 0
2 years ago
What does an engineer do? List as many types of engineers as you can.
BARSIC [14]

Answer:

Mechanical Engineering

Chemical Engineering

Civil Engineering

Explanation:

I got it from my old homework And I learn those at school ( Thank You For The Points)

7 0
2 years ago
Which of the following does the electrical technician typically use?​
kkurt [141]

Answer:

What are the choices?

8 0
2 years ago
Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation.
Juliette [100K]

Answer:

THE CODE FOR THE PROGRAM IS GIVEN BELOW:

#include <iostream>

#include "ConvertTimeHeader.h"

using namespace std;

int main()

{

convertTime convert;

int hr, mn, sc = 0;

 

cout << "Please input hours in 12 hr notation: ";

cin >> hr;

cout << "Please input minutes: ";

cin >> mn;

cout << "Please input seconds: ";

cin >> sc;

 

convert.invalidHr(hr);

convert.invalidMin(mn);

convert.invalidSec(sc);

convert.printMilTime();

 

system("Pause");

 

return 0;  

 

}

#include <iostream>

#include "ConvertTimeHeader.h"

using namespace std;

int convertTime::invalidHr (int hour)

{

try{

 if (hour < 13 && hour > 0)

  {hour = hour + 12;

  return hour;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input hour again in correct 12 hour format: ";

  cin >> hour;

  invalidHr(hour);

  throw 10;

 }

   

}

catch (int c) { cout << "Invalid hour input!";}

}

int convertTime::invalidMin (int min)

{

try{

 if (min < 60 && min > 0)

  {return min;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input minutes again in correct 12 hour format: ";

  cin >> min;

  invalidMin(min);

  throw 20;

  return 0;

 }

   

}

catch (int e) { cout << "Invalid minute input!" << endl;}

}

int convertTime::invalidSec(int sec)

{

try{

 if (sec < 60 && sec > 0)

  {return sec;}

 else{

 

  cin.clear();

  cin.ignore();

  cout << "Invalid input! Please input seconds again in correct 12 hour format: ";

  cin >> sec;

  invalidSec(sec);

  throw 30;

  return 0;

 }

   

}

catch (int t) { cout << "Invalid second input!" << endl;}

}

void convertTime::printMilTime()

{

cout << "Your time converted: " << hour << ":" << min << ":" << sec;

}

Explanation:

4 0
3 years ago
Which material has the highest cp value?
Nataly [62]

Answer: B. Water

Explanation:

6 0
2 years ago
Other questions:
  • A small truck is to be driven down a 4% grade at 70 mi/h. The coefficient of road adhesion is 0.95, and it is known that the bra
    7·1 answer
  • The rate of energy transfer by work is called power. a)-True b)-False
    15·1 answer
  • "The office personnel at Garden Glory use a database application to record services and related data changes in this database. F
    9·1 answer
  • It is possible to have liquid water at 200°C. a)-True b)- False
    14·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
  • Consider a building whose annual air-conditioning load is estimated to be 40,000 kWh in an area where the unit cost of electrici
    8·1 answer
  • A continuous function y = ƒ(x) is known to be negative at x = 0 and positive at x = 1. Why does the equation ƒ(x) = 0 have at le
    14·1 answer
  • Overconfidence in more male drivers, particularly those under 25 years old, results in them being involved in crashes.
    14·1 answer
  • 2.<br> The most common way to identify size of pipe is by:
    8·1 answer
  • Algorithm for sum 2+4+6+….+n
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!