Tensor in Pytorch

type
status
date
slug
summary
tags
category
icon
password
😀
In this note, I talk about tensor in pytorch, and all code can be seen in my github repo: .or in the famous repo: My repo has more content than this note, I will transport them later.

📝Set up

As a libarary of python, we can just import libaray “troch”:
If you want to use “gym” for developing and comparing reinforcement leanrning, please refer to
And orther supports:

📝Tensor in pytorch

If you are not familiar with tensor, please check the last note Introduction
This gives:
Orther usage can be checked in torch.Tensor — PyTorch 2.9 documentation
The answer is 0.
A scalar(torch.tensor(a natrual number)), has no dimension.
The result is 7
This shows what is in torch.tensor (relation of tensor() and tensor().item() is kind of like a set and elements in this set.
The result is tensor([6, 7])
And a matrix is similiar.
tensor([[11, 12], [21, 22]])
torch.Size([2, 2])
But if we look at a tensor of order 3, it is a little deceptive.
For example
tensor([[[11, 12, 13], [21, 22, 23], [31, 32, 33]]])
It looks like a 3*3 matrix, however,
torch.Size([1, 3, 3])
What is 1,3,3? We can sepearate each “[]”.
1 means there is one matrix
3 means there is 3 vector
3 means there is 3 scalar
And another example makes it clearer:
torch.Size([1, 2, 3])
1 matrix(in this tensor of order 3), 2 vectors(in each matrix), 3 scalar(in each vector).
And
shows Error:
After reading the first [11,13], torch.tensor confirms the dimension of vector being 2. So different children-dimension is forbbiden.
 
观点2
引用的话语

🤗 总结归纳

总结文章的内容

📎 参考文章

  • 一些引用
  • 引用文章
 
💡
有关Notion安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~
Prev
Introduction
Next
Stack and Heap
Loading...
Article List
About this Notes
Basic Concepts
SDK install and env config
Journey of Rust
Algorithm
Stochastic Process and Diffusion Model
CUDA Basic Usage
DeepLearning&Pytorch