我正在開發(fā)一種軟件來(lái)創(chuàng)建具有這種結(jié)構(gòu)的矩陣:[[2020-07-14 13:01:58.535695, 9.013799869442407, 989.5936121308639], [2020-07-14 14:40:05.144901, 59.27540855766542, 463.4158524443841]]要構(gòu)建第一行,數(shù)組應(yīng)包含:[2020-07-14 13:01:58.535695,2020-07-14 14:40:05.144901]為了連接這些日期時(shí)間,我這樣做:x_vet = [] for z in range(self.n_samples): self.x_0 = datetime.now() totaltime = self.x_0 + timedelta(milliseconds = self.period) x_vet.append(self.x_0 + totaltime) self.signals_data.append(x_vet)錯(cuò)誤是:類型錯(cuò)誤:+ 不支持的操作數(shù)類型:“datetime.datetime”和“datetime.datetime”所以我嘗試在代碼中這樣做:x_vet.append(str(self.x_0) + str(totaltime))但是str()我只得到 1 個(gè)這樣的元素:'2020-07-14 14:35:44.0007892020-07-14 14:35:44.010789'我想得到這個(gè)x_vet:[2020-07-14 13:01:58.535695,2020-07-14 14:40:05.144901] 因?yàn)檎麄€(gè)軟件被構(gòu)建為識(shí)別x_vet為 2 個(gè)元素的數(shù)組此錯(cuò)誤僅出現(xiàn)在數(shù)據(jù)時(shí)間對(duì)象中,因?yàn)橐婚_始我已經(jīng)嘗試使用 float 我的程序并且正在運(yùn)行并返回:[[0.0, 9.013799869442407, 989.5936121308639], [0.01, 59.27540855766542, 463.4158524443841]]
1 回答

qq_笑_17
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊
你是這個(gè)意思嗎?
x_vet = []
for z in range(self.n_samples):
self.x_0 = datetime.now()
totaltime = self.x_0 + timedelta(milliseconds = self.period)
x_vet.append(totaltime)
self.signals_data.append(x_vet)
添加回答
舉報(bào)
0/150
提交
取消