Python Forum

Full Version: General list size question to solve problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
Thank you so much.
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.