sferes2 / map_elites

** Sferes2 module ** MAP-Elites module for Sferes2
Other
21 stars 7 forks source link

Fixed Numpy indexing error by casting to integers #5

Closed fsaev closed 8 years ago

fsaev commented 8 years ago

I got this error when running the script:

./sferes2/Candycane_2016-03-08_18_10_39_8508/archive_5.dat
Traceback (most recent call last):
  File "plot_map.py", line 40, in <module>
    data[round(x[i] * size), round(y[i] * size)] = z[i]
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

I think it's due to some changes in Numpy. The reason to why this is happening is because the value of round(x[i] * size) is 1.0, not the integer 1, which can be seen in pdb:

../GaitAdaptation/sferes2/Candycane_2016-03-08_18_10_39_8508/archive_5.dat
> /home/gavekort/map_elites/plot_map.py(41)<module>()
-> data[int(round(x[i] * size)), int(round(y[i] * size))] = z[i]
(Pdb) p round(x[i] * size)
1.0

This was easily fixed by casting the value to an integer.