• Register
0 votes

Problem :

I am having below error in a title, and I don't know what's wrong. It was working when I used np.hstack instead of the np.append, but I want to make this faster, so using append.

time_list the list of floats

heights is the 1d np.array of floats

File "....", line .., in <module>

TypeError: only integer arrays with one element can be converted to an index


3.9k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

The issue is just as a error indicates, time_list is the normal python list, and hence you cannot index it using the another list (unless your other list is the array with single element).

If you want to do that kind of indexing then you would need to make your time_list the numpy.array. As shown below

In [141]: time_list = np.array(time_list)

In [142]: time_list[np.arange(5,6)]

Out[142]: array([6])

In [143]: time_list[np.arange(5,7)]

Out[143]: array([6, 7])

Another important thing to note is that in the while loop, you never increase the j, so it may end-up with the infinite loop , you should also increase the j by some amount (maybe by time_interval).

But according to your requirement you posted in comments -

axe_x should be the 1d array of floats generated from a time_list list

You must use .extend() instead of your .append() , .append would create the list of arrays for you. But if you need the 1D array, you need to use the .extend().

38.6k points