Title: if (data[i,1] == 1): IndexError: index 869 is out of bounds for axis 0 with size 869
Tags: python;numpy;import
Question: I have the following code:
def findingGroups(data,i=0):
findingGroupsMatrix1=np.zeros(1)
findingGroupsMatrix2=np.zeros(1)
findingGroupsMatrix3=np.zeros(1)
findingGroupsMatrix4=np.zeros(1)
z=np.zeros(1)
print ("i",i)
while True:
if (data[i,1] == 1):
z[0]=i
findingGroupsMatrix1=np.append(findingGroupsMatrix1,z,axis=0)
elif data[i,1] == 2:
z[0]=i
findingGroupsMatrix2=np.append(findingGroupsMatrix2,z,axis=0)
elif data[i,1] == 3:
z[0]=i
findingGroupsMatrix3=np.append(findingGroupsMatrix3,z,axis=0)
elif data[i,1] == 4:
z[0]=i
findingGroupsMatrix4=np.append(findingGroupsMatrix4,z,axis=0)
elif i == len(data):
break
i=i+1
And this is the error:  if (data[i,1] == 1):
IndexError: index 869 is out of bounds for axis 0 with size 869
an data is a numpy.ndarray and shape (869, 10) . could u please help me to solve the problem.
Comment: Sterling answer from @SterlingArcher

Comment: Your break test should come first.

Comment: If the size if 869, that means that index 868 is the last accessible index because arrays are zero-indexed.

Here is the accepted answer: If the shape is (869, 10), then the first subscripts run from 0-868.  Your loop control is faulty.  Since you know how many times you're going through the loop, use a "for".  The loop you have checks after it's too late.
for i in len(data):
....
You don't have to increment i any more.
Also, note that you only checked the index if the second element is not in the range 1-4.  This could also cause your loop to fail.

Here is another answer: python zero indexes. this means that the "first" element of an 869 element array is at 0, and the last pamelamorales@example.com. hence, referencing 869 will fail. use the search feature next time; this question could have been fixed by simply looking at python documentation, or previous questions, rather than posting on stack.
Comment for this answer: The program is in Python -- which also uses 0-based indexing.  Tea break?
Comment for this answer: hadn't even read the question once i saw the error tbh because it was so generic. assumed java
Comment for this answer: I'm sorry, Java..?! I mean you're not wrong, but wrong language.

Here is another answer: If the shape of the array is (869, 10), then the largest index in the object is at (868, 9) (since indexing starts at 0 as is typical with python sequences).

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:10/26/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><numpy><import>', 'Title': 'if (data[i,1] == 1): IndexError: index 869 is out of bounds for axis 0 with size 869', 'ViewCount': 176, 'id': 33356001, 'user_AboutMe': None, 'user_AccountId': 7089987.0, 'user_DisplayName': 'Talia ', 'user_Reputation': 2647.0, 'user_Views': 94.0, 'user_id': 5425511.0}}