当前位置:网站首页>Pytorch summary learning series - data manipulation
Pytorch summary learning series - data manipulation
2022-06-29 09:21:00 【TJMtaotao】
In deep learning , We usually do data entry frequently ⾏ That's ok 行 operation . Act as ⼿ Hand learning is the foundation of deep learning , This section describes how to do this internally
The data in the memory goes into ⾏ That's ok 行 operation .
stay PyTorch in , torch.Tensor Is the main way to store and transform data ⼯ Tools . If you had ⽤ Used to NumPy, You'll find that
Tensor and NumPy Multidimensional array of ⾮ Very similar . however ⽽, Tensor Provide GPU The calculation and ⾃ Automatic gradient Wait a minute 更 multi-function , this
Some emissaries Tensor more 更 It is suitable for deep learning .
tensor It means tensor , A multidimensional tensor is a multidimensional array , Scalar is 0 D tensor , A vector is a 1 D tensor , A matrix is a two-dimensional tensor .

establish TENSOR
First, import. PyTorch:
import torch
And then we establish One 5x3 Of Uninitialized Tensor :
x = torch.empty(5, 3)
print(x)
Output :
tensor([[ 0.0000e+00, 1.5846e+29, 0.0000e+00],
[ 1.5846e+29, 5.6052e-45, 0.0000e+00],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00],
[ 0.0000e+00, 0.0000e+00, 0.0000e+00],
[ 0.0000e+00, 1.5846e+29, -2.4336e+02]])
establish ⼀ One 5x3 Of Randomly initialized Tensor :
Output :
tensor([[0.4963, 0.7682, 0.0885],
[0.1320, 0.3074, 0.6341],
[0.4901, 0.8964, 0.4556],
[0.6323, 0.3489, 0.4017],
[0.0223, 0.1689, 0.2939]])
establish ⼀ One 5x3 Of long Type all 0 Of Tensor :
x = torch.zeros(5, 3, dtype=torch.long)
print(x)
Output :
tensor([[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
Create directly from the data :
x = torch.tensor([5.5, 3])
print(x)
Output :
tensor([5.5000, 3.0000])
just so so Through the existing Tensor To create , this ⽅ Method defaults to redo ⽤ Use transport ⼊ Enter into Tensor Of ⼀ Some properties , example 例 Such as data type , except ⾮ Not
⾃ Custom data types .
x = x.new_ones(5, 3, dtype=torch.float64) # Back to tensor The default has the same
torch.dtype and torch.device
print(x)
x = torch.randn_like(x, dtype=torch.float) # Specify a new data type
print(x)
Output :
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=torch.float64)
tensor([[ 0.6035, 0.8110, -0.0451],
[ 0.8797, 1.0482, -0.0445],
[-0.7229, 2.8663, -0.5655],
[ 0.1604, -0.0254, 1.0739],
[ 2.2628, -0.9175, -0.2251]])
adopt shape perhaps size() To get Tensor The shape of the :
print(x.size())
print(x.shape)
Output :
torch.Size([5, 3])
torch.Size([5, 3])
Be careful : Back to torch.Size In fact, that is ⼀ One tuple, ⽀ Support all tuple The operation of .
Many functions can be created Tensor , Go to the official ⽅https://pytorch.org/docs/1.2.0/torch.htmlAPI You know the 了, The following table gives 了⼀ Some often ⽤ For reference .


These create ⽅ Methods can specify the data type when creating dtype And storage device(cpu/gpu).
边栏推荐
- MySQL row column conversion example
- Record the field name dynamically modified by SetData of wechat applet
- Wechat applet opens file stream
- Laravel 8 enables the order table to be divided by month level
- YOLACT实时实例分割
- Augfpn: improved multiscale feature learning for target detection
- Wechat applet user refuses to authorize geographic location information and calls up the authorization window again
- 深卷积神经网络时代的目标检测研究进展
- Activemq消息组件发布订阅ReDelivery消息重新投递
- (转)MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
猜你喜欢

Universal target detection based on region attention

Wechat applet custom multi selector

Lffd: a lightweight fast face detector for edge detection

调试H5页面-vConsole

Activemq消息组件发布订阅ReDelivery消息重新投递

图片格式-webp

mysql insert 时出现Deadlock死锁场景分析

YOLO Nano:一种高度紧凑的只看一次的卷积神经网络用于目标检测

Wechat applet latest canvas2d handwritten signature

Detecting and counting tiny faces
随机推荐
调试H5页面-weinre及spy-debugger真机调试
pytorch总结学习系列-操作
Verilog splicing operation symbol
微信小程序跳转公众号图文内容
Picture format -webp
Record the field name dynamically modified by SetData of wechat applet
SSD improvements cfenet
ServerApp.iopub
The difference between cokkie and session
H5 soft keyboard problem
Verilog shift operator
[target detection] | indicator a probabilistic challenge for object detection
笔试题“将版本号从大到小排列”
Difference between factory mode and strategy mode
Verilog equivalent operator
UE4 插件报错 Cannot open include file: ‘ModuleManager.h‘解决
Open3d hidden point removal
微信小程序分享页面,分享到朋友圈
Scenario analysis of deadlock during MySQL insert
微信小程序搜索关键字高亮和ctrl+f搜索定位实现