欢迎光临散文网 会员登陆 & 注册

【PyTorch】Tensor&Variable

2022-09-09 22:33 作者:安然Nano  | 我要投稿

从重新过一遍PyTorch,记录会稍晚同步到blog.qhpersonal.top

Initializing a Tensor

Attribute of Tensor

Three attributs is stored: shap, datatype, the device

Tensor and Numpy Conversions

numpy() : Tensor --> Numpy

torch.from_numpy(): Numpy --> Tensor

Operation on Tensor

tensor.to("cuda"): To GPU

cat(): Connect

stack(): Superposition. And stack make the dim up one.

Arithmetic Operations

Multiplication

matrix: tenser @ tensor, tensor.matmul()    // tensor.mm() only use two matrix mul

element-wise product: tensor * tensor, torch.mul()

Others

tensor.sum(): Sum by the specified dim

.item(): single-element tensors --> python numerical value

tensor.add_(): add ? and store the result

参考资料:

[1]Welcome to PyTorch Tutorials[EB/OL]. (2022-09-09)[2022-09-09]. https://pytorch.org/tutorials.


【PyTorch】Tensor&Variable的评论 (共 条)

分享到微博请遵守国家法律