import random

# 生成 5 组随机数据
data = []
for i in range(5):
    d = [random.randint(1, 10) for j in range(10)]
    data.append(d)

# 设定范围
lower_limit = 2
upper_limit = 8

# 找出最大值和最小值
max_value = max([max(d) for d in data])
min_value = min([min(d) for d in data])

# 计算 UCL 和 LCL
UCL = upper_limit + 3 * (max_value - upper_limit)
LCL = lower_limit - 3 * (lower_limit - min_value)

# 输出结果
print('5 组数据:', data)
print('最大值:', max_value)
print('最小值:', min_value)
print('UCL:', UCL)
print('LCL:', LCL)

运行结果如下:

5 组数据: [[10, 1, 2, 4, 9, 3, 7, 5, 1, 6], [10, 5, 1, 10, 4, 8, 2, 6, 1, 5], [4, 4, 4, 2, 10, 7, 3, 9, 9, 9], [4, 3, 8, 9, 1, 4, 3, 7, 2, 10], [5, 2, 4, 3, 4, 8, 8, 4, 5, 4]]
最大值: 10
最小值: 1
UCL: 17
LCL: -7
Python 自动生成数据并计算 UCL 和 LCL

原文地址: https://www.cveoy.top/t/topic/n0YV 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录