我正在尝试计算可变大小数组的原点和偏移量,并将它们存储在字典中。以下是我实现这一目标的可能的非Python式方法。我不确定是否应该使用map、lambda函数或列表理解来使代码更具Python式。
从本质上讲,我需要根据总大小对数组进行切块,并将xStart、ystart、x-number、x-number和y-number存储到字典中。总大小是可变的。我不能将整个数组加载到内存中并使用numpy索引,否则我肯定会这样做。原点和偏移量用于使数组变为numpy。
intervalx = xsize / xsegment #Get the size of the chunks
intervaly = ysize / ysegment #Get the size of the chunks
#Setup to segment the image storing the start values and key into a dictionary.
xstart = 0
ystart = 0
key = 0
d = defaultdict(list)
for y in xrange(0, ysize, intervaly):
if y + (intervaly * 2) < ysize:
numberofrows = intervaly
else:
numberofrows = ysize - y
for x in xrange(0, xsize, intervalx):
if x + (intervalx * 2) < xsize:
numberofcolumns = intervalx
else:
numberofcolumns