Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a python function to perform the following tasks: 1. set the seed of the numpy random number generator to 1234 2. define Q to

Write a python function to perform the following tasks:

1. set the seed of the numpy random number generator to 1234

2. define Q to be a 200 x 200 matric with normally distributed random entries having zero mean and unit variance (use numpy.random.normal)

3. loop through each element of Q (remember that there are two dimensions). If the element is negative, make it positive by replacing it with its square (i.e. set Q|i,j| to Q|i,j|^2 if Q|i,j| < 0). But don't change the positive entries of Q. (use for and if. could you perform the same operation using only one line of code?)

4. now define r to be a 200 x 1 column vector of uniformly distributed numbers between 0 and 1 (using numpy.random.uniform)

5. now define 200 x 1 vector z = Q * r (using matrix-vector product)

6. define p to be the mean value of the element-wise product between r and z^2 (i.e. the average over j or r|j| z|j|^2). You should be able to do this in one line. use the built-in function, numpy.mean, to take the mean.

you should get a single positive number as the result

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago