【发布时间】:2022-11-17 13:14:54
【问题描述】:
我有一个清单
points = [[6033.02, -24791.2], [7008.29, -24257.0], [7128.66, -23434.0], [7235.19, -22899.3], [6590.0, -22308.7]]
和
centre = [37621.265, -32837.66499999999]
我想用这个函数翻译点的值
def translate(center, points):
new_points_x = []
new_points_y = []
new_points = []
for i in points:
# print(str(i[0]))
new_points_x.append(i[0]-center[0])
for i in points:
new_points_y.append(i[1]-center[1])
for i in range(0,len(new_points_x)):
new_points.append([new_points_x[i], new_points_y[i]])
return new_points
它给我错误
TypeError: 'float' object is not subscriptable
我为浮动索引尝试了很多东西但都失败了。
【问题讨论】:
-
你有什么问题?请阅读How to Ask。如果您正在寻找调试帮助,您需要制作一个 minimal reproducible example,包括完整但最少的代码、预期输出和 full error message with traceback。当我尝试
translate(centre, points)时,我没有得到那个错误。也许你传递了一些错误的东西,比如你把论点弄反了?
标签: python python-3.x