在Python中从3D到2D

2024-09-30 08:34:42 发布

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

我想要这个代码:

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))

像这样:

^{pr2}$

好的,我已经解决了代码问题,但现在我有一个错误:

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的最后一个数,而不是第一个,但也许这不是产生这个错误的真正问题


Tags: the代码inforreturn错误rangeaddr
1条回答
网友
1楼 · 发布于 2024-09-30 08:34:42

现在还不完全清楚你想做什么,什么不起作用,但有些奇怪的是你改变了:

return x + (nx) * (y + (ny) * (z))

进入:

^{pr2}$

不应该是:

return x + (nx) * y

相反呢?考虑到nz没有出现在你的3D版本中,ny不应该出现在2D版本中。在

相关问题 更多 >

    热门问题