pytorch入門- tensor基礎操作(1)

HDU平頭哥發表於2020-10-03
  1. 建立tensor

建立指定元素的tensor:
torch.tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False)
建立隨機元素的tensor:
torch.rand(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
建立服從正態分佈N(0,1)的tensor:
torch.randn(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
建立在0—(n-1)之間隨機整數的tensor:
torch.randperm(n, out=None, dtype=torch.int64, layout=torch.strided, device=None, requires_grad=False)
建立指定區間low到high的tensor:
torch.randint(low=0, high, size, *, generator=None, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)

  1. 操作tensor

拼接tensor,dim=0表示按行拼接,dim=1表示列拼接
torch.cat(tensors, dim=0, out=None)
裁剪tensor
torch.split(tensor, split_size_or_sections, dim=0)
ps: split_size_or_sections的詳細介紹
在這裡插入圖片描述

相關文章