簡體   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)

我正在嘗試從給定SPLIT_SIZE = 0.9的列表中抽取隨機樣本,但我遇到以下錯誤:TypeError: can't multiply sequence by non-int of type'float'。 這是給出錯誤的代碼行:

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

SOURCE是一個包含圖像的目錄。

我將不勝感激任何幫助!!

random.sample的第二個參數必須是 integer 類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM