有效值计算czy
import numpy as np
def cal_d(all_jj):
print("所有报价:{0}".format(all_jj))
all_jj.sort(reverse=True);
print("所有报价,由高到低排序后:{0}".format(all_jj))
arr_length = len((all_jj))
a = [i for i in range(arr_length)][:arr_length - 1]
cz_1 = [(all_jj[i] - all_jj[i + 1]) for i in a]
print("报价差值:{0}".format(cz_1))
cz_1.sort(reverse=True);
print("报价差值由高到低排序:{0}".format(cz_1))
print("所有差值数量:{0}".format(len(cz_1)))
czsl_30 = len(cz_1) * 0.3
print("小数点后第一位四舍五入后取整,取整前:{0}".format(czsl_30))
czsl_30 = round(czsl_30)
print("小数点后第一位四舍五入后取整,取整后:{0}".format(czsl_30))
cz_1 = cz_1[:czsl_30]
print("前30%的差值:{0}".format(cz_1))
sspjz = np.mean(cz_1)
print("算术平均值,即组距D值:{0}".format(sspjz))
return sspjz
def do_group(all_jj, zj_d):
target_arr = []
all_jj.sort(reverse=True);
while len(all_jj) > 0:
arr = [x for x in all_jj if x > all_jj[0] - zj_d]
target_arr.append(arr)
for i in arr:
all_jj.remove(i)
print("分组结果:{}".format(target_arr))
return target_arr
if __name__ == '__main__':
# 模拟报价
all_jj = [36000, 43523, 32432, 45433, 40000, 34000, 35435, 36000, 35754, 35426, 36784, 39863, 42352, 36000, 35754,
35426, 36784, 39863, 42352]
zj_d = cal_d(all_jj)
# 确定有效值
group_result = do_group(all_jj, zj_d)
mean_arr = []
for i in group_result:
if len(i) > 0:
mean_value = np.mean(i)
print("分组{0}的均值:{1}".format(i, mean_value))
mean_arr.append(mean_value)
print("分组均值:{}".format(mean_arr))
mean_arr.sort(reverse=True);
print("分组均值--排序后:{}".format(mean_arr))
s = int(len(mean_arr) / 5) - 1
print("{0} < 分组数 <= {1}".format(5 * s, 5 * (s + 1)))
k = 2 + s
print("K = {}".format(k))
print("====== 有效值 = {}".format(mean_arr[-k]))
https://www.w3cschool.cn/tryrun/runcode?lang=python3

浙公网安备 33010602011771号