• Register
0 votes
457 views

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>
axe_x.append(time_list[np.arange(j+n,j+(time_interval-n))])

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

 

7 5 2
3,870 points

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().

9 7 4
38,600 points

Related questions

2 votes
2 answers 221 views
221 views
Problem: I wrote the following code in python using numpy. But it gives me some error message. The code I wrote is: import numpy as np arrayone = np.array(['Human', 'Birds', 'Groots', 'Oats']) arraytwo = np.array(['Beach', 'Toast']) arraythree ... concatenate TypeError: only integer scalar arrays can be converted to a scalar index Can anyone sort out this error and solve this. Thanks in advance.
asked May 6 samhaz 5k points
0 votes
1 answer 250 views
250 views
I was trying to write a programm using numpy and matplotlib. I am new to python programming. The code I wrote is: import numpy import matplotlib.pyplot def ThisFunction(a): return numpy.int(a) a = numpy.arange(3, 13.5, 0.7) matplotlib.pyplot.plot(a, ... 4, in ThisFunction return numpy.int(a) TypeError: only size-1 arrays can be converted to Python scalars how can I solve this problem?
asked Mar 15 LizzyM 6.1k points
0 votes
1 answer 1.9K views
1.9K views
Problem : I am getting below error: TypeError: only length-1 arrays can be converted to Python scalars How can I fix it?
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 1.6K views
1.6K views
Problem : I am trying to convert my list into an array using Python, But I got below error ValueError: only one element tensors can be converted to Python scalars.
asked Oct 22, 2019 peterlaw 6.9k points