Question: Write a python function to perform the following tasks: Set the seed of the numpy random number generator to 1 2 3 4 . Define

Write a python function to perform the following tasks:
Set the seed of the numpy random number generator to 1234.
Define
to be a
matrix with normally distributed random entries having zero mean and unit variance (use numpy.random.normal).
Loop through each element of
(remember that there are two dimensions). If the element is negative, make it positive by replacing it with its square (i.e., set
to
if
). But don't change the positive entries of
.(Use for and if. Could you perform the same operation using only one line of code in python?).
Now define
to be a
column vector of uniformly distributed numbers between 0 and 1(using numpy.random.uniform).
Now define the
vector
(using matrix-vector product).
Define
to be the mean value of the element-wise product between
and
(i.e., the average over
of
). You should be able to do this in one line. Use the built-in function, numpy.mean, to take the mean.
Run the script.
Debug any errors you see.
You should get a single positive number as the result. Please report your code and show a printout of the result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!