You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'numpy.ndarray' object has no attribute 'index' #293
On line 1683 in pygad.py the code says solution_idx = self.best_solutions.index(list(sol))
apparently assuming that self.best_solutions is always a list. However, it is possible that self.best_solutions is a numpy.ndarray, in which case the index method is undefined and the program crashes.
Adding
if type(self.best_solutions) is numpy.ndarray:
self.best_solutions = self.best_solutions.tolist()
before the first if statement (if (self.save_solutions) and (len(self.solutions) > 0) and (list(sol) in self.solutions):) seems to resolve the issue.
The saved-best-solution lookup now handles NumPy arrays instead of calling the list-only .index() method on them. I verified repeated multi-objective save/load/run cycles with saved best solutions enabled, without the reported AttributeError. I am closing this as fixed.
Activity
ahmedfgad commentedon Jan 7, 2025
Thanks. This is going to be fixed in the next release!
PyGAD 3.4.0
ahmedfgad commentedon Oct 8, 2026
The saved-best-solution lookup now handles NumPy arrays instead of calling the list-only
.index()method on them. I verified repeated multi-objective save/load/run cycles with saved best solutions enabled, without the reported AttributeError. I am closing this as fixed.