当前位置:网站首页>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).
边栏推荐
- Abstract classes and interfaces
- [to.Net] C data model, from Entity Framework core to LINQ
- SSD改進CFENet
- Open3D 最远点采样(FPS)
- Augfpn: amélioration de l'apprentissage des caractéristiques à plusieurs échelles pour la détection des cibles
- Wechat applet jump to official account image and text content
- Simple use of promise method
- 查找字符串中重复次数最多的元素
- 什么是超融合?与传统架构有什么区别?.
- SSD improvements cfenet
猜你喜欢

Ue4 installe le plug - in datasmith dans la version 4.20-23

Detecting and counting tiny faces

Uni app gets the route URL of the current page

【目标检测】|指标 A probabilistic challenge for object detection

来个小总结吧

MT yolov6 training and testing

Lffd: a lightweight fast face detector for edge detection

两阶段目标检测原理详细版

Open3d farthest point sampling (FPS)

Highlight in the middle of the navigation bar at the bottom of wechat applet
随机推荐
微信小程序最新canvas2d手写签名
(转)MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
MYSQL虚拟列
微信小程序分享页面,分享到朋友圈
Activemq消息组件发布订阅ReDelivery消息重新投递
Professional structure record
Pat (basic level) practice (Chinese) 1003 I want to pass! (20 points) C language implementation
Keras to tf Vgg19 input in keras_ shape
Mongodb persistence
CMD enter virtual machine
train_on_batch保存一下loss函数变化的图像
Member inner class, static inner class, local inner class
Wechat applet project: wechat applet page layout
Pointnet/pointnet++ training and testing
js轮播图观后重做(较长的完整版,可运行)
Summary of IO streams
记微信小程序分享代码片段
Solutions to ineffective uniapp import components
两阶段目标检测原理详细版
使用GPU训练kernel切换