我有两天时间试图解决此问题,而没有任何改善。 我有下面的代码:
if qtd > qtd_individuos:
distancia_mutidao = crowding_distance(fitness)
print("Distância de mutidão: \n{} População: \n{} Fitness: \n{}".format(distancia_mutidao, pop, fitness))
while (len(pop) > qtd_individuos):
menor_ = distancia_mutidao.argmin()
pop = np.delete(pop, menor_)
fitness = np.delete(fitness, menor_)
distancia_mutidao = np.delete(distancia_mutidao, menor_)
其中distancia_mutidao,pop和Fitness是NumPy数组。我正在尝试从矩阵distancia_multidao,pop和fitness中删除相应的较低值。 我正在绘制这些值,我得到了:
Distância de mutidão:
[1. 0.15555981 0.11988209 0.09177397 1. 0.14718105
0.08688929 0.14825755 0.01990456 0.11109479 0.02420551 0.22930752
0.16252269 0.29968407 0.03971115] População:
[[1 3 1 3 2 1 2 1 1 2 1 1 1 1 2]
[3 3 3 3 1 1 3 1 3 2 1 3 2 3 2]
[2 3 3 2 1 2 1 1 2 3 1 1 3 1 1]
[1 3 2 1 2 1 1 3 3 2 3 1 3 2 1]
[3 3 2 3 2 3 1 2 1 2 2 3 3 3 2]
[3 1 1 1 3 3 2 3 2 2 3 1 2 1 3]
[1 3 2 1 2 1 1 3 3 2 3 1 3 1 3]
[3 1 1 1 3 3 2 3 2 2 3 2 2 2 3]
[2 3 3 2 1 2 1 1 2 3 1 1 3 1 1]
[3 1 1 1 3 3 2 3 2 2 3 1 2 2 1]
[2 1 2 3 3 2 3 3 2 1 3 1 2 1 3]
[3 1 1 1 3 3 2 2 2 3 2 3 3 3 3]
[2 1 1 1 1 2 3 2 2 1 3 3 2 2 3]
[2 1 3 1 1 2 3 3 2 1 3 1 2 2 1]
[1 3 2 3 2 1 1 3 3 2 3 1 3 2 1]] Fitness:
[[ 8. 58.73167024]
[19. 49.34529535]
[12. 55.08177469]
[14. 53.10238747]
[20. 46.55252601]
[16. 51.15094548]
[15. 51.74934794]
[18. 49.47316082]
[12. 55.08177469]
[15. 52.503985 ]
[17. 51.2657001 ]
[20. 47.5785755 ]
[14. 53.62171346]
[13. 55.32419517]
[16. 51.44574786]]
因此,矩阵distancia_mutidao不为空...为什么出现此错误“ ValueError:尝试获取空序列的argmin”?