TypeError: float object has no attribute __getitem__,python

TypeError: float object has no attribute __getitem__,python

The __getitem__ is a special python function which is equivalent to the operator [] or the indexing or the get item operator.

So, the error is basically saying that there is a variable which is a float. And to this variable youve called the __getitem__ function – probably by doing an index operator to it.

Based on the traceback which shows the line dot_B_x = pulp.lpSum([B[i][j] * x[j] for j in range(n)]) as the culprit, it seems either B, B[i], or x would be the probable issue

pulp.lpSum([B[i][j] * x[j] for j in range(n)])

TypeError: float object has no attribute __getitem__

Which means that either B, B[i] or x are floats, and you cant use [] on these.

TypeError: float object has no attribute __getitem__,python

Leave a Reply

Your email address will not be published.