首页 新闻 会员 周边 捐助

关于python中嵌套for循环转map的问题

0
悬赏园豆:100 [待解决问题]

本人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)
lvwei3的主页 lvwei3 | 初学一级 | 园豆:102
提问于:2020-06-24 15:32
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册