1.1
In [17]:
a=range(0,102,2)
print(list(a))
a=list(a)
a.reverse()
print(a)
In [18]:
#1.2
a[44]='Happy'
a[-1]='Friday'
print(a)
In [8]:
#1.3
b=list(range(6,27,1))
print(b)
c=a+b
print(c)
In [9]:
#1.4
import numpy as np
first_quarter=(len(c)//4)
print('The mean of the first quarter is',np.mean(c[:first_quarter]))
In [10]:
#1.5
print(np.arange(300).reshape((100,3)))
In [37]:
#1.6
x=np.linspace(0,np.pi,400)
print(np.cos(x))
In [11]:
#2.1
import matplotlib.pyplot as plt
years=np.arange(1998,2020,2)
plt.plot(years,np.sin(years))
plt.show()
In [16]:
#2.2
domain=np.arange((-np.pi+0.1),np.pi,0.1)
#print(domain)
plt.plot(domain,np.sin(domain),'r')
plt.plot(domain,np.cos(domain),'b')
plt.plot(domain,np.sin(2*domain),'y')
plt.plot(domain,np.cos(2*domain),'g')
Out[16]:
In [49]:
#2.3
#domain=np.arange(-np.pi,np.pi,0.1)
domain_1=np.linspace(-np.pi,np.pi,4)
domain_2=np.linspace(-np.pi,np.pi,6)
domain_3=np.linspace(-np.pi,np.pi,8)
domain_4=np.linspace(-np.pi,np.pi,32)
#print(domain)
plt.plot(domain_1,np.sin(domain_1),'r')
plt.plot(domain_2,np.sin(domain_2),'b')
plt.plot(domain_3,np.sin(domain_3),'y')
plt.plot(domain_4,np.sin(domain_4),'g')
Out[49]:
In [101]:
#3.1
P=[0.2,0.3,0.1,0.4] #will save the probabilities of each height
E_height=np.sum(195*P[0]+180*P[1]+168*P[2]+170*P[3])
print('The expected value is:',E_height)
Variance=-E_height**2+np.sum(195**2*P[0]+180**2*P[1]+168**2*P[2]+170**2*P[3])
print('The variance is:',Variance)
In [102]:
#3.2
p=[0.1,0.2,0.4,0.3,0.2]
gpa=[100,95,80,75,75]
E_gpa=0
for i in range(len(p)):
E_gpa+=p[i]*gpa[i]
print('the expected value of the grade is:',E_gpa)
$Z=\int_{-2}^{2}(-x^2+4)dx=\int_{-2}^{2}(-x^2+4)dx=(\frac{-x^3}{3}+4x)|_{-2}^{2}=[-\frac{8}{3}+4\cdot2]-[\frac{-8}{3}+4\cdot(-2)]$=16 $E(x)=\frac{\int_{-2}^{2}x*(-x^2+4)dx}{Z}=\frac{\int_{-2}^{2}(-x^3+4x)dx}{16}=\frac{(\frac{-x^4}{4}+2x^2)|_{-2}^{2}}{16}=\frac{[-\frac{16}{4}+2\cdot2^2]-[-\frac{16}{4}+2\cdot(-2)^2]}{16}=0$
In [94]:
#3.4
numbers=[6,5,4,3,2,1]
#print(np.mean(numbers))
prob_number=[0.3, 0.25, 0.1, 0.1, 0.2, 0.05]
expected_number=0
for i in range(len(numbers)):
expected_number+=numbers[i]*prob_number[i]
print('The expected value of the array is',expected_number)
In [96]:
#3.5
prob=[0.5,0.5]
print(prob)
profit=[4,-2]
expected_grade=(np.array(profit)*prob)
print('the expected profit for the company is:', sum(expected_grade))
In [ ]: