我在讀pyTorch文檔(三)

數據類型

  1. CPU數據類型:torch.FloatTensor(torch.Tensor),torch.DoubleTensor,torch.ByteTensor,torch.CharTensor,torch.ShortTensor,torch.IntTensor,torch.LongTensor;
  2. GPU數據類型:torch.cuda.FloatTensor,torch.cuda.DoubleTensor,torch.cuda.HalfTensor,torch.cuda.ByteTensor,torch.cuda.CharTensor,torch.cuda.ShortTensor,torch.cuda.IntTensor,torch.cuda.LongTensor;

數據類型操作

  1. 從python的list或者序列構建Tensor:torch.FloatTensor([[1, 2, 3], [4, 5, 6]]);
  2. 指定大小構建Tensor:torch.FloatTensor.zero_();
  3. x.abs()和x.abs_() :前者生成副本,後者in-place運算,其他大量函數同理;
  4. y = x.byte():將tensor改爲byte類型;
  5. y = x.char():將tensor改爲char類型;
  6. y = x.clone() :返回與x有相同大小和數據類型的tensor;
  7. y = x.contiguous() :返回一個內存連續的有相同數據的tensor;
  8. x.copy_(y,async):複製拷貝操作,x和y應該有相同數目的元素,可以是不同的數據類型或存儲在不同的設備上;
  9. y = x.cpu() :如果在CPU上沒有x,則會返回一個CPU的副本;
  10. y = x.cuda(device, async):返回GPU副本,async=True並且資源在固定內存中,則複製的副本將會與原始數據異步;
  11. y = x.data_ptr():返回第一個元素地址;
  12. y = x.dim():返回維度;
  13. y = x.element_size():返回單個字節大小;
  14. 我在讀pyTorch文檔(二)中包含的數學操作基本都有y=x.function()版本或者y=x.function_()版本;
發佈了32 篇原創文章 · 獲贊 47 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章