Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q4. Write a python code to do the following operations. 1. Create a 1000 x 1000 matrix A. Each element of the matrix is a
Q4. Write a python code to do the following operations. 1. Create a 1000 x 1000 matrix A. Each element of the matrix is a random integer in the range (1, 100) 2. Convert the type of the matrix elements from integer to floating point. 3. Create the matrix B by doing the following element-wise operation on A AAij Bij sin Ajj where By and Aij denote the elements of B and A. You are required to do this element-wise operation explicitly by loop over the elements of B and A. Print the first element of B and get the time for creating this B in unit of nanosecond. 4. Create the same matrix B by Numpy element-wise operation. Print the first element of B and get the time for creating this B in unit of nanosecond. 5. Let's call the matrix B created in Q4.3 B, and the matrix B created in Q4.4 B. Although B and B2 are created in different ways, they should be identical in principle. In order to check if they are really identical, we can look at the Frobenius norm of the relative error: B In the above expression, all the operations inside . || are element-wise. Evaluate this Frobenius norm and check if the relative error is small. (5 X 4 = 20 marks)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started