亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將張量列表轉換為張量的張量 pytorch

將張量列表轉換為張量的張量 pytorch

繁星點點滴滴 2022-10-18 19:49:33
我有這個代碼:import torchlist_of_tensors = [ torch.randn(3), torch.randn(3), torch.randn(3)]tensor_of_tensors = torch.tensor(list_of_tensors)我收到錯誤消息:ValueError:只有一個元素張量可以轉換為 Python 標量如何將張量列表轉換為 pytorch 中的張量張量?
查看完整描述

2 回答

?
互換的青春

TA貢獻1797條經驗 獲得超6個贊

您還可以將火炬張量類型轉換為 NumPy 數組,然后將它們轉換為張量


list_of_tensors = [torch.randn(3).numpy(),torch.randn(3).numpy(),torch.randn(3).numpy()]

tensor_of_tensors = torch.tensor(list_of_tensors)


查看完整回答
反對 回復 2022-10-18
?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

這是一個解決方案:

tensor_of_tensors = torch.stack((list_of_tensors))
print(tensor_of_tensors) #shape (3,3)


查看完整回答
反對 回復 2022-10-18
  • 2 回答
  • 0 關注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號