Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: attempt to get argmax of an empty sequence

Tags:

python

I get the following error when running the code below.

ValueError: attempt to get argmax of an empty sequence

The code is processing information from images sent to it from simulator.

It runs well at first but when the array Rover.nav_angles is empty i get the error although there is an if condition

if Rover.nav_angles is not None:
        Max_angle_points=np.argmax(Rover.nav_angles)
        MAX_DIST=np.max(Rover.nav_dists[Max_angle_points])
like image 670
Ahmed Gendy Avatar asked Sep 21 '17 13:09

Ahmed Gendy


1 Answers

Use:

if Rover.nav_angles:
    ...

To check for emptiness and None. But it seems that you deal with numpy array so use:

if Rover.nav_angles.size:
    ...
like image 196
zipa Avatar answered Sep 27 '22 20:09

zipa