Skip to content

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

Open
@GaidaiIgor

Description

@GaidaiIgor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions