Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

python - TypeError: 'float' object cannot be interpreted as an index, how to solve it?

The error message is:

File "dry.py", line 1184, in < module >
grid = getmap(grid)
File "dry.py", line 690, in getmap
data = array(data, 'f').reshape(pts[2], pts[1], pts[0])
TypeError: 'float' object cannot be interpreted as an index

I'd appreciate any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...