给代码每行后面注释from scipy.stats import norm from numpy import * n=36 mu = 70 sigma = 15 xbar = 66.5 alpha = 0.05 rig = 1-alpha/2 left = alpha/2 z = (xbar-mu)/(sigma/sqrt(n))q1 = norm.ppf(left,,1)q2 = norm.ppf(rig,,1) if q1 <= z <= q2:print('Accept xbar = mu')else: print('Not accept xbar = mu')print(q1,q2)print(z)
时间: 2024-03-18 10:43:35 浏览: 70
Python错题本:from scipy.misc import imread 报错cannot import name imread 的解决方案
# 导入norm函数用于正态分布的概率密度函数和累计分布函数的计算
from scipy.stats import norm
# 导入numpy库中的sqrt函数用于计算样本数的平方根
from numpy import *
# 样本量为36,总体均值为70,总体标准差为15,样本均值为66.5
n = 36
mu = 70
sigma = 15
xbar = 66.5
# 设置显著性水平为0.05,计算左侧和右侧的临界值
alpha = 0.05
rig = 1 - alpha / 2
left = alpha / 2
# 计算样本均值的z分数
z = (xbar - mu) / (sigma / sqrt(n))
# 计算左侧和右侧的临界值对应的z分数
q1 = norm.ppf(left)
q2 = norm.ppf(rig)
# 判断样本均值的z分数是否落在临界值范围内
if q1 <= z <= q2:
print('Accept xbar = mu')
else:
print('Not accept xbar = mu')
# 打印左侧和右侧的临界值以及样本均值的z分数
print(q1, q2)
print(z)
阅读全文