File size: 875 Bytes
dfe37be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import json
# 读取 JSON 文件
with open('humaneval_new.json', 'r') as file:
data = json.load(file)
# 提取属性 A 的值
values_of_A = [obj['line'] for obj in data]
# 计算属性 A 的范围
min_A = min(values_of_A)
max_A = max(values_of_A)
# 确定区间数量和宽度
num_intervals = 3
interval_width = (max_A - min_A) / num_intervals
# 划分区间
intervals = [(min_A + i * interval_width, min_A + (i + 1) * interval_width) for i in range(num_intervals)]
# 将数据分配到各个区间
subsets = [[] for _ in range(num_intervals)]
for obj in data:
value_A = obj['line']
for i, (start, end) in enumerate(intervals):
if start <= value_A < end:
subsets[i].append(obj)
break
with open('EI.json', 'w', encoding='utf-8') as file:
json.dump(data, file, ensure_ascii=False, indent=4) |