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,260 points
6,050 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,460 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 9, 2019 in Machine Learning by Mishra
1,104 views
0 votes
1 answer

Real world applications of Machine Learning

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

answered May 10, 2019 in Machine Learning by Jinu
835 views
0 votes
1 answer

What are different types of regressions?

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

answered May 10, 2019 in Machine Learning by Jinu
3,231 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
11,851 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 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,790 points
4,071 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 19, 2020 in Machine Learning by MD
• 95,460 points
1,081 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,460 points
5,502 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP