我怎样才能转移
A = [0.12075357905088335, -0.192198145631724, 0.9455373400335009, -0.6811922263715244, 0.7683786941009969, 0.033112227984689206, -0.3812622359989405]
至
A = [[0.12075357905088335], [-0.192198145631724], [0.9455373400335009], [-0.6811922263715244], [0.7683786941009969], [0.033112227984689206], [-0.3812622359989405]]
我尝试了下面的代码,但发生了错误:
new = []
for i in A:
new.append.list(i)
TypeError: 'float' object is not iterable
谁能帮帮我?
原文由 FlyingBurger 发布,翻译遵循 CC BY-SA 4.0 许可协议
tl;博士
尝试 list comprehension ,它更方便:
解释
您得到
TypeError
因为您不能将list()
函数应用于float
类型的值。 此函数 将可迭代对象作为参数,并且float
不是可迭代对象。Another mistake is that you are using
new.append._something
instead ofnew.append(_something)
:append
is a method of alist
object, so you should provide an作为参数添加的项目。