Python TypeError:float()参数必须是字符串或数字,而不是';列表';
我的代码在这里:Python TypeError:float()参数必须是字符串或数字,而不是';列表';,python,tensorflow,Python,Tensorflow,我的代码在这里: temp = np.array([images, labels]) temp = temp.transpose() np.random.shuffle(temp) image_list = list(temp[: 0]) label_list = list(temp[: 1]) label_list=[int(float(i)) for i in label_list] return image_list, label_list spder给出错误:TypeError:f
temp = np.array([images, labels])
temp = temp.transpose()
np.random.shuffle(temp)
image_list = list(temp[: 0])
label_list = list(temp[: 1])
label_list=[int(float(i)) for i in label_list]
return image_list, label_list
spder给出错误:TypeError:float()参数必须是字符串或数字,而不是“list”
有人知道怎么解决吗?非常感谢您的
标签列表
是一个列表列表
label_list = list(temp[: 1])
这应该是:
label_list = temp[:1]
然后,当您在label_list中为i调用
时,i
将填充对象而不是列表 你不该切的时候却在切。这些线路是错误的:
image_list = list(temp[: 0])
label_list = list(temp[: 1])
切片意味着要将二维数组转换为数组列表(即使列表中可能只有一个数组)。我想你想要同样的东西,没有冒号:
image_list = list(temp[0])
label_list = list(temp[1])
这里是索引(而不是切片),因此您正在将1D数组转换为单个非嵌套列表,我认为这正是您所需要的。如果您纠正了这一点,您将错误地为标签和图像列表创建一个列表,否则一切都会正常工作。不要将列表
传递到float
?