Python Forum
General list size question to solve problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General list size question to solve problem
#1
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.
Reply
#2
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
Reply
#3
Thank you so much.
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can someone help me solve this programming problem? SuchUmami 6 833 Nov-20-2023, 10:01 AM
Last Post: EdwardMatthew
  A simple problem, how best to solve it? SuchUmami 2 683 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  python can - general question caslor 0 1,095 Jul-14-2022, 05:21 PM
Last Post: caslor
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,178 Jun-14-2022, 08:35 PM
Last Post: thesquid
  How do I solve the second problem? Cranberry 1 1,092 May-16-2022, 11:56 AM
Last Post: Larz60+
  Problem with "Number List" problem on HackerRank Pnerd 5 2,034 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  a general question barryjo 5 1,442 Feb-01-2022, 10:12 PM
Last Post: Gribouillis
  Try to solve GTG multiplication table problem. Frankduc 6 1,937 Jan-18-2022, 08:26 PM
Last Post: Frankduc
  General Programming Question with Dictionary giddyhead 12 2,589 Jan-10-2022, 10:12 AM
Last Post: Pedroski55
Big Grin General programming question (input string)[ jamie_01 2 1,569 Jan-08-2022, 12:59 AM
Last Post: BashBedlam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020