Question
Python3 code question Change the code such that it prints the mean and variance of your samples, using Numpy functions. You are only required to
Python3 code question
Change the code such that it prints the mean and variance of your samples, using Numpy functions. You are only required to add these two lines in this python file. These two to-do lines are in bold font. This is in python3. Thank you in advance
from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import random import sys
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 = 0 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
from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import random import sys # default dim - 1 - 100 numsamples 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]) + str(dim), print("Running with dim - " and numsamples = " + str(numsamples)) # Generate data from (Univariate) Gaussian if dim -- 1: # mean and standard deviation in one dimension mu - 0 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
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