我有这个代码:
for times in range(50):
factor = (min(getHeight(),getWidth()) / math.sqrt(qtdPosicoes)) * guess()
positionInGrid = {}
grid = np.zeros((getGridColumns(),getGridLines()))
groupMatrix = np.zeros((grid.shape[0], grid.shape[1]))
groups = getGroups(grid, listaComPosicoes, getXRanges(listaComPosicoes),getYRanges(listaComPosicoes))
solution = calculaSilhueta()
if bestSolution is None or solution > bestSolution:
bestSolution = solution
Run Code Online (Sandbox Code Playgroud)
我在文档时间模块中找到了但我不明白如何使用
我正在使用 np.nonzero() 并且我不明白返回
我试试
for groupPosition in np.nonzero(groupMatrix):
print groupPosition
Run Code Online (Sandbox Code Playgroud)
并返回 [0 0 1 2 3 3 3]
for groupPosition in zip(np.nonzero(groupMatrix)):
print groupPosition
Run Code Online (Sandbox Code Playgroud)
并返回 (array([0, 1, 0, 3, 0, 1, 3]),)
组矩阵:
[[ 1. 1. 0. 0.]
[ 1. 0. 0. 0.]
[ 0. 0. 0. 2.]
[ 3. 3. 0. 2.]]
Run Code Online (Sandbox Code Playgroud)
但是不要像 (0, 0) 那样返回位置