Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'numpy.ndarray' object has no attribute 'index' #293

Open
GaidaiIgor opened this issue Jul 4, 2024 · 0 comments
Open

'numpy.ndarray' object has no attribute 'index' #293

GaidaiIgor opened this issue Jul 4, 2024 · 0 comments

Comments

@GaidaiIgor
Copy link

GaidaiIgor commented Jul 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant