索引41超出大小为41的轴0的界限

2024-04-26 21:22:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我追踪到了错误代码。 我能把数据[z,y,x]改成数据[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

请帮帮我。。。。说真的我不明白。。。 你能找出我的错误吗?你知道吗


Tags: inptfordatascanifcoordsmin