-
-
Notifications
You must be signed in to change notification settings - Fork 968
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
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() #192
Comments
I am also running into this issue with the PSO class: def update_pbest(self):
E ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() ../../../.local/lib/python3.11/site-packages/sko/PSO.py:151: ValueError I am, however, really monkeying around a bit by making a hybrid optimizer though so this could be a result of my meddling. Thank you for such a well-written, intuitive, and useful package! Mikaela |
After some investigation, I've highlighted that the issue arises after the first iteration: while I haven't cloned the code to debug it yet (If maintainers would appreciate a fix and pull request on this then I could do so), it seems that in the first iteration it works properly, self.need_update is size (pop_size, 1) array, but in the second iteration it returns (pop_size, pop_size) arrray of booleans. Looks like it is because self.pbest_y is a 2-dimensional array with shape (pop_size, 1) but self.Y is a 1-dimensional array of length pop_size, so effectively shape (1, pop_size) I think. It's a quick fix in the definition of self.Y but I do now notice that this is a bug inherently different from the one in this thread, so I will open a new one. Thank you! |
File "C:\software\anconda\lib\site-packages\sko\GA.py", line 57, in
penalty_ueq = np.array([np.sum(np.abs([max(0, c_i(x)) for c_i in self.constraint_ueq])) for x in self.X])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The text was updated successfully, but these errors were encountered: