(Python 版本 2.6.5)
我有:
boxes_with_sizes_added = [\
[0,0,0,1,1,1,0],\
[785,500,200,787,502,202,1],\
[400,500,600,404,504,604,2],\
[100,200,300,108,208,308,3],\
[50,60,70,51,61,71,0]\
# several millions more...
]
...它们是格式为 [x1,y1,z1,x2,y2,z2,rel_size] 的框
我有一个“切碎”的方法:
def cubic_breakdown(box,division_factor):
if division_factor==1:
return[box]
elif division_factor>1:
boxes_out=[]
for k in range(division_factor):
for j in range(division_factor):
for i in range(division_factor):
boxes_out.append([\
(box[0]+((box[3]-box[0])/float(division_factor))*i),\
(box[1]+((box[4]-box[1])/float(division_factor))*j),\
(box[2]+((box[5]-box[2])/float(division_factor))*k),\
(box[0]+((box[3]-box[0])/float(division_factor))*(i+1)),\
(box[1]+((box[4]-box[1])/float(division_factor))*(j+1)),\
(box[2]+((box[5]-box[2])/float(division_factor))*(k+1)),\
box[6]\
])
return boxes_out
其中基本上一个“盒子”根据它的“rel_size”被“切碎”成相等的段并添加到列表中
chopped_boxes=[]
for box in boxes_with_sizes_added:
for chopped_box in cubic_breakdown(box,2**box[6]):
chopped_boxes.append(chopped_box)
但是,当我尝试处理太多的盒子时,我会在某个时候收到“MemoryError”。问题是什么?我需要腌制我的列表或列表输出吗?提前致谢!