Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is a python 3 file. I just need the last TODO line to get the estimate of the sample mean and sample variance.I am
This is a python 3 file.
I just need the last TODO line to get the estimate of the sample mean and sample variance.I am only allowed to add those two lines.
I tried to add code below print('Mean is: ',x.mean())
print('Standard deviation is: ',np.std(x))
I tried those two lines but it keeps getting a value error. what else could I use?
from mpl_toolkits.mplot3d import Axes 3D import matplotlib.pyplot as plt import numpy as np import random import sys def plot_gaussian(x, y, filename=None): Plot the multivariate Gaussian If filename is not given, then the figure is not saved. # Note: there was no need to make this into a separate function # however, it lets you see how to define functions within the # main file, and makes it easier to comment out plotting if # you want to experiment with many parameter changes without # generating many, many graphs fig - plt.figure ax = fig.add_subplot(111) ax.scatter(x,y, C="red",marker="s") ax.set_xlabel("X") ax.set_ylabel("Y") minlim, maxlim = -3, 3 ax.set_xlim(minlim, maxlim) ax.set_ylim(minlim, maxlim) if filename is not None: fig. savefig("scatter" + str(dim) + "_n" + str(numsamples) + ".png") plt.show() if __name__ == '__main__': # default dim = 1 numsamples - 100 if len(sys.argv) > 1: dim = int(sys.argv[1]) if dim > 3: print("Dimension must be 3 or less; capping at 3") if len(sys.argv) > 2: numsamples = int(sys.argv[2]) print("Running with dim = " + str(dim), \ " and numsamples - " + str(numsamples) # Generate data from (Univariate) Gaussian if dim -- 1: # mean and standard deviation in one dimension mu - 9 sigma = 1.0 x - np.random.normal (mu, sigma, numsamples) y = np.zeros(numsamples,) else: # mean and standard deviation in three dimension print("Dimension not supported") exit(0) #TODO: Get the current estimate of the sample mean #TODO: Get the current estimate of the sample variance # Print all in 2d space plot_gaussian(x,y) #plot_gaussian(x,y,"scatter" + str(dim) + "_n" + strnumsamples) + ".png">
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