IndexError tuple index out of range

0 votes

Hi Guys,

I have one Machine Learning model, which detects my face. It detects my face but sometimes I am getting this below error.

IndexError                                Traceback (most recent call last)
<ipython-input-2-41b72326245f> in <module>
----> 1 y = x[0][0]
IndexError: tuple index out of range
Apr 15, 2020 in Machine Learning by akhtar
• 38,170 points
4,135 views

1 answer to this question.

0 votes

Hi@akhtar,

I don't know your use cases. But you may got this error when your tuple don't have any value. For an Example.

>>>x = ()
>>>y = x[0]
IndexError                                Traceback (most recent call last)
<ipython-input-3-5679abac6acb> in <module>
      1 x = ()
----> 2 y = x[0]
IndexError: tuple index out of range

Here I am trying to assign an empty tuple to y. So I am getting this error. But You can avoid this error using if else condition.

if len(x)==0:
    pass
else:
    print('your code')

Hope this will help you.

answered Apr 15, 2020 by MD
• 95,160 points

Related Questions In Machine Learning

0 votes
1 answer

Are there different types of reinforcements?

There are two types of reinforcements - ...READ MORE

answered May 8, 2019 in Machine Learning by Mishra
187 views
0 votes
1 answer

Real world applications of Machine Learning

Few real-world applications of machine learning are  Have ...READ MORE

answered May 9, 2019 in Machine Learning by Jinu
221 views
0 votes
1 answer

What are different types of regressions?

There are three types of regressions: Linear regression: Linear ...READ MORE

answered May 9, 2019 in Machine Learning by Jinu
579 views
0 votes
1 answer

Different types of Logistic Regression

There are three main types of logistic ...READ MORE

answered May 13, 2019 in Machine Learning by Nikhil
8,428 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,032 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,554 views
0 votes
1 answer

Train-test split with 20% of data set aside - ML

Hi@Kim, You can use the train_test_split function to ...READ MORE

answered Jul 18, 2020 in Machine Learning by MD
• 95,160 points
207 views
+1 vote
1 answer

not able to see all columns and rows of a pandas DataFrame?

Hi@akhtar, Your data set contains lots of rows ...READ MORE

answered Apr 8, 2020 in Machine Learning by MD
• 95,160 points
2,046 views