Python Forum
General list size question to solve problem - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: General list size question to solve problem (/thread-29958.html)



General list size question to solve problem - Milfredo - Sep-27-2020

I really appreciate all of the help I have gotten here. Need more.I have a list:
horses_info =  []
I run my program and append elements to the list. When I get to the following:

def extract_horse_data(horse_count):

                                    , horses_info.append(xx[horse_count][98])
it throws the following error. I have not anywhere in my code given the list any dimension limit.

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Milford\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "pyfuncs.py", line 190, in select_track
load_track_to_Handi()
File "pyfuncs.py", line 159, in load_track_to_Handi
extract_horse_data(horse_count)
File "pyfuncs.py", line 101, in extract_horse_data
horses_info.append( xx[horse_count][96]),horses_info.append( xx[horse_count][97]), horses_info.append(xx[horse_count][98]),
IndexError: index 98 is out of bounds for axis 0 with size 98

I know what the error is saying, But I did not create the list with any dimensions at all.


RE: General list size question to solve problem - bowlofred - Sep-27-2020

xx[horse_count] is not a list but a numpy array. It's telling you the numpy array has size 98. That means since the array is zero-indexed, the largest index you can request is 97. Asking for xx[horse_count][98] is too big.

>>> arr = np.ones(98)
>>> arr[97]
1.0
>>> arr[98]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: index 98 is out of bounds for axis 0 with size 98



RE: General list size question to solve problem - Milfredo - Sep-27-2020

Thank you so much.


RE: General list size question to solve problem - Milfredo - Sep-27-2020

The problem turned out to be, I added data points to the code, but was trying to read csv file with less data points in the line. Got it working fine now. Thank you again.