[英]TypeError: float() argument must be a string or a number, not 'list'
My code is here:我的代码在这里:
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
And spder give the error :TypeError: float() argument must be a string or a number, not 'list'并且 spder 给出错误:TypeError: float() 参数必须是字符串或数字,而不是“列表”
Anyone know how to solve it?有谁知道如何解决它? Thank you very much
非常感谢
Your label_list
is a list of lists.您的
label_list
是一个列表列表。
label_list = list(temp[: 1])
This should instead be:这应该是:
label_list = temp[:1]
Then when you call for i in label_list
, i
will be populated with the object rather than a list.然后,当您
for i in label_list
调用for i in label_list
, i
将填充对象而不是列表。
You're slicing when you shouldn't be.你在不应该切片的时候切片。 These lines are wrong:
这些行是错误的:
image_list = list(temp[: 0])
label_list = list(temp[: 1])
The slices mean that you're transforming a 2D array in to a list of arrays (even though there's probably only one array in the list).切片意味着您正在将二维数组转换为数组列表(即使列表中可能只有一个数组)。 I think you want the same thing without the colons:
我认为你想要没有冒号的同样的东西:
image_list = list(temp[0])
label_list = list(temp[1])
Here's you're indexing (rather than slicing), so you're transforming a 1D array into a single non-nested list, which I think is what you want.这是您正在索引(而不是切片),因此您将一维数组转换为单个非嵌套列表,我认为这就是您想要的。
如果您更正该列表,那么您就错误地为标签和图像列表制作了列表,然后一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.