import numpy as np import torch import matplotlib.pyplot as plt Quiz Preparation Question 1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor. 2. Write a code (for loop) that call that calls the function above with n = 2, 4, 8, 16,... 1024 and generate a vector M(n). Plot the vector as a function of the log of n. 3. Given an n x m array write a code that replaces every element that is larger than 0.5 with 0.5. 4. The second derivative of a function can be approximated by the finite difference ƒ"(x;) = 7/3 (ƒ(£;;1) — 2ƒ(2;) + ƒ(2;-1)) - h² Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x) 5. The power method is a method to compute the largest eigenvalue of a matrix. Your google search is using this method every time you perform a google search. The method consists of the iteration Avj Vj+1 || Av;|| where v; is a vector with v chosen as a random vector, and A is the matrix that we seek its eigenvalue/eigenvector. The iteration is terminated when ||Vj+1-vj|| < tol where tol is a specified tolerance. Write a python program that gets A, a matrix and tol, a tolerance and returns the estimated eigenvector v Note that to multiply matrix and a vector you can use the matmul(A,v) or A@v

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
import numpy as np
import torch
import matplotlib.pyplot as plt
Quiz Preparation Question
1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor.
= 2, 4, 8, 16, ... 1024 and generate a vector
2. Write a code (for loop) that call that calls the function above with n =
M(n).
Plot the vector as a function of the log of n.
3. Given an n x m array write a code
that replaces every element that is larger than 0.5 with 0.5.
4. The second derivative of a function can be approximated by the finite difference
1
ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1))
Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x)
5. The power method is a method to compute the largest eigenvalue of a matrix.
Your google search is using this method every time you perform a google search.
The method consists of the iteration
Vj+1 =
Av;
|| Avi||
where v; is a vector with chosen as a random vector, and A is the matrix that we seek its eigenvalue/eigenvector. The
iteration is terminated when
||Vj+1-vj|| < tol
where tol is a specified tolerance.
Write a python program that gets A, a matrix and tol, a tolerance and returns the estimated eigenvector v
Note that to multiply matrix and a vector you can use the matmul(A,v) or A@v
Transcribed Image Text:import numpy as np import torch import matplotlib.pyplot as plt Quiz Preparation Question 1. Write a function that generates a random tensor of n x n (n is the input). The output is the mean of the tensor. = 2, 4, 8, 16, ... 1024 and generate a vector 2. Write a code (for loop) that call that calls the function above with n = M(n). Plot the vector as a function of the log of n. 3. Given an n x m array write a code that replaces every element that is larger than 0.5 with 0.5. 4. The second derivative of a function can be approximated by the finite difference 1 ƒ"(x₂) = 73 (ƒ(£;+1) — 2ƒ(x;) + f(x;-1)) Given a vector f with values f = [f(xo),..., f(n) write a code that computes the approximation to f"(x) 5. The power method is a method to compute the largest eigenvalue of a matrix. Your google search is using this method every time you perform a google search. The method consists of the iteration Vj+1 = Av; || Avi|| where v; is a vector with chosen as a random vector, and A is the matrix that we seek its eigenvalue/eigenvector. The iteration is terminated when ||Vj+1-vj|| < tol where tol is a specified tolerance. Write a python program that gets A, a matrix and tol, a tolerance and returns the estimated eigenvector v Note that to multiply matrix and a vector you can use the matmul(A,v) or A@v
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education