Mengyuan Liu
Upload 71 files
dfe37be verified
raw
history blame contribute delete
875 Bytes
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)