本人python小白,刚接触1个多月;想把下面这个嵌套for循环转成map提高效率,有大神帮忙解决吗?
nx = 4000
ny = 2240
resultarray = []
for i in range(0,nx):
for k in range(0,10):
xkarr=[]
for j in range(k*224,(k+1)*224):
if pic[i][j] !=-1000000:
xkarr.append(pic[i][j])
x=range(len(xkarr))
y = xkarr
poly = np.polyfit(x, y, deg=2)
if k==0:
for zro in range(224 - len(xkarr)):
resultarray.append(0)
nhx = range(len(xkarr))
for r in nhx:
realy = pic[i][r + 224 - len(xkarr)]
nhy = np.polyval(poly, r)
if realy - nhy > 2.5:
rval = 255
elif realy - nhy < -2.5:
rval = 255
else:
rval = 0
resultarray.append(rval)
else:
nhx = range(k * 224, (k + 1) * 224)
for r in nhx:
realy = pic[i][r]
nhy = np.polyval(poly, r - k * 224)
if realy - nhy > 10000:
rval = 0
if realy - nhy < -10000:
rval = 0
elif realy - nhy > 1.5:
rval = 255
elif realy - nhy < -1.5:
rval = 255
else:
rval = 0
resultarray.append(rval)