简体   繁体   English

尝试将浮点数与 len(list) 相乘时,无法将序列乘以“float”类型的非整数错误

[英]can't multiply sequence by non-int of type 'float' ERROR when trying to multiply a float number with len(list)

I'm trying to take a random sample from a list given SPLIT_SIZE = 0.9 , but im having the following error: TypeError: can't multiply sequence by non-int of type 'float'.我正在尝试从给定SPLIT_SIZE = 0.9的列表中抽取随机样本,但我遇到以下错误:TypeError: can't multiply sequence by non-int of type'float'。 this is the line of code that is giving the error:这是给出错误的代码行:

list = os.listdir(SOURCE)
training_set = random.sample(list, float(SPLIT_SIZE)*int(len(list)))

SOURCE BEING A DIRECTORY containing images. SOURCE是一个包含图像的目录。

I would appreciate any help!!我将不胜感激任何帮助!!

The second argument of random.sample have to be integer type. random.sample的第二个参数必须是 integer 类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM