iT邦幫忙

1

Python 陣列列表轉浮點數

https://ithelp.ithome.com.tw/upload/images/20191008/20121658dPxQogZjYc.jpghttps://ithelp.ithome.com.tw/upload/images/20191008/201216582E9M3mAkmj.jpg
目前想將第一張照片內容希望能變成第二張照片的浮點數,但當我使用float(x)或haarFeatures = list(map(float, haarFeatures))轉換浮點數時會出現ValueError: could not convert string to float:說我無法將字串轉為float
請問有方法還是哪部分我可能需要做修改 請求解答 Thank you

ccutmis iT邦高手 2 級 ‧ 2019-10-08 12:51:11 檢舉
str_lst = [ '2.000000' , '45.000000' , '8.400000' , '1.230000' ]
float_lst = [float(x) for x in str_lst]
print(str_lst)
print(float_lst)
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
黃彥儒
iT邦高手 1 級 ‧ 2019-10-08 12:02:19

float(int(x))
我看你的資料都是.0,為何不用int就好,運算上有需要他會自己轉

我要發表回答

立即登入回答