简体   繁体   English

类型错误:float() 参数必须是字符串或数字,而不是“列表”

[英]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_listi将填充对象而不是列表。

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.

相关问题 Python-TypeError:float()参数必须是字符串或数字,而不是'list - Python - TypeError: float() argument must be a string or a number, not 'list 类型错误:float() 参数必须是字符串或数字,而不是“列表”python - TypeError: float() argument must be a string or a number, not 'list' python TypeError:float()参数必须是字符串或具有列表总和的数字 - TypeError: float() argument must be a string or a number with list sum 类型错误:float() 参数必须是字符串或数字,而不是“Day” - TypeError: float() argument must be a string or a number, not 'Day' 类型错误:float() 参数必须是字符串或数字,而不是“配置文件” - TypeError: float() argument must be a string or a number, not 'Profile' 类型错误:float() 参数必须是字符串或数字,而不是“Period” - TypeError: float() argument must be a string or a number, not 'Period' TypeError:float()参数必须是字符串或数字,而不是'方法' - TypeError: float() argument must be a string or a number, not 'method' TypeError:float() 参数必须是字符串或数字,而不是“SimpleImputer” - TypeError: float() argument must be a string or a number, not 'SimpleImputer' TypeError: float() 参数必须是字符串或数字,而不是“Tensor” - TypeError: float() argument must be a string or a number, not 'Tensor' TypeError:float() 参数必须是字符串或数字,而不是“类型” - TypeError: float() argument must be a string or a number, not 'type'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM