第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù)

無法將字符串轉(zhuǎn)換為浮點(diǎn)數(shù)

人到中年有點(diǎn)甜 2022-01-18 21:32:40
我需要從服務(wù)器獲取 GPU-Power。這應(yīng)該通過 nvidia-smi 完成。  def getGpuPower(self):      splitedGpuPower = os.popen("nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits").read().replace("\n", ",").split(",")      for x in range(4):        self.gpuPower += float(splitedGpuPower[x])      return self.gpuPower我需要一個(gè)像 250,00 這樣的浮點(diǎn)數(shù)我實(shí)際上得到(  File "test1.py", line 22, in getGpuPower    self.gpuPower += float(splitedGpuPower[x])ValueError: could not convert string to float:)輸出看起來像這樣$ nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits8.507.4311.04
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊

假設(shè)您的輸出os.popen("nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits").read()is 8.50\n7.43\n11.04,以下應(yīng)該有效。


def getGpuPower():

      #Split on newline

      splitedGpuPower = "8.50\n7.43\n11.04".split("\n")

      gpuPower = 0

      #Iterate through the list

      for power in splitedGpuPower:

          #If string is non empty, convert to float and add

          if power.strip() != '':

              gpuPower += float(power)

      print(gpuPower)

輸出將是


getGpuPower()

#26.97


查看完整回答
反對(duì) 回復(fù) 2022-01-18
  • 1 回答
  • 0 關(guān)注
  • 297 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)