Typeerror: 'float' Object Cannot Be Interpreted As An Index, How To Solve It?
Solution 1:
can you write in your question an example of what the values of pts[0], pts[1], pts[2] looks like?
if the values are close to integers (like 1.00004 or 3.9998) you can use the round function to round the values to the nearest integer like:
data = array(data, 'f').reshape(round(pts[2]), round(pts[1]), round(pts[0]))
Solution 2:
The function numpy.reshape
takes int
or tuple of ints. You are trying to pass float
. But you can't.
By the way you can cast your float object to int like int(pts[0])
Solution 3:
Check the type of pts[i]
(for i
in [0,1,2]
)
Are these int
s or float
s? int
s are needed for this API.
If you find floats that are very close to an integer like 3.0
or 2.99
then clearly int
s were intended.
Simply use int(pts[i])
instead of pts[i]
(and/or check how these indexes were converted to float
).
If you find values that were not meant to be int
, like 2.4
, then you will need to debug that.
Post a Comment for "Typeerror: 'float' Object Cannot Be Interpreted As An Index, How To Solve It?"