索引41超出大小为41的轴0的范围

时间:2018-11-13 11:34:58

标签: python ubuntu index-error

回溯后出现错误代码。 我可以将data [z,y,x]更改为data [0,0,0]吗? 然后,它起作用了。

Traceback (most recent call last):
  File "/home/suhui/Downloads/dry.py", line 1194, in <module>
    harvest, affinity = getpoints(grid, coord(w), distance = 1.0) # angstroms
  File "/home/suhui/Downloads/dry.py", line 739, in getpoints
    harvesting.append( data[z,y,x] )
IndexError: index 41 is out of bounds for axis 0 with size 41

这是我的代码。

pt_scan = int( round(float(distance)/(spacing)) )
if pt_scan == 0: pt_scan = 1 # at least one point around
if DEBUG: print "Grid range: %2.2f [ +/- %d points : %2.2f ]" % (distance,pt_scan, pt_scan*spacing), 
best = 999

if (coords[0] < max[0]) and (coords[0] > min[0]):
    if (coords[1] < max[1]) and (coords[1] > min[1]):
        if (coords[2] < max[2]) and (coords[2] > min[2]):
            z_pt = int(round((coords[2] - min[2])/spacing))
            y_pt = int(round((coords[1] - min[1])/spacing))
            x_pt = int(round((coords[0] - min[0])/spacing))

            for x_ofs in range(-pt_scan, pt_scan+1): 
                x = x_pt + x_ofs
                if x < 0 :
                    harvesting.append(0)
                    break
                for y_ofs in range(-pt_scan, pt_scan+1): 
                    y = y_pt + y_ofs
                    if y < 0 :
                        harvesting.append(0)
                        break
                    for z_ofs in range(-pt_scan, pt_scan+1): 
                        z = z_pt + z_ofs
                        if z < 0 :
                            harvesting.append(0)
                            break
                        harvesting.append( data[z,y,x] )
                        if data[z,y,x] < best:
                            best = data[z,y,x]
        if DEBUG: print " %d pts [ best: %2.2f ]" % (len(harvesting), best),
        return harvesting, best
return False

请帮助我...。严重的是我听不懂... 你能找到我的错误吗?

0 个答案:

没有答案