我想要这个代码:
chains3D = [[] for k in range(colors)]
def addr(x,y,z): return x + (nx) * (y + (ny) * (z))
for x in range(nx):
for y in range(ny):
for z in range(nz):
if (image[x,y,z] == background):
chains3D[1].append(addr(x,y,z))
else:
chains3D[0].append(addr(x,y,z))
在这样的事情中:
chains2D = [[] for k in range(colors)]
def addr(x,y): return x + (nx) * y
for x in range(nx):
for y in range(ny):
if (image[x,y,0] == background):
chains2D[1].append(addr(x,y))
else:
chains2D[0].append(addr(x,y))
好的,我已经解决了代码问题,但现在我遇到了这个错误:
IndexError Traceback (most recent call last)
<ipython-input-5-6a7d44bd72b7> in <module>()
213 objectBoundaryChain = larBoundaryChain(partial_3,chains2D[1])
214 b2cells = csrChainToCellList(objectBoundaryChain)
--> 215 sup_cell_boundary = MKPOLS((V,[FV[f] for f in b2cells]))
216
217 # remove the (local) boundary (shared with the piece boundary) from the quotient cell
/Users/Fabio/larpy/lar.pyc in MKPOLS(model)
101 """
102 V, FV = model
--> 103 pols = [MKPOL([[V[v] for v in f],[range(1,len(f)+1)], None]) for f in FV]
104 return pols
105
IndexError: list index out of range
我不知道为什么 f 等于 b2cells 的最后一个数量,而不是第一个,但也许这不是产生此错误的真正问题