当前位置:网站首页>Torch learning notes (1) -- 19 common ways to create tensor
Torch learning notes (1) -- 19 common ways to create tensor
2022-07-03 18:22:00 【ZRX_ GIS】
import torch
import numpy as np
''' tensor (Tensor) tensor It's a multidimensional array , He is a scalar 、 vector 、 High dimensional extension of matrix , among , Scalar is 0 D tensor , The vector is 1 D tensor , Matrix is 2 D tensor ,RGB Image is 3 D tensor . tensor There are three kinds of creation methods : Direct type 、 Based on numerical formula 、 Based on probability formula '''
# 1、 Direct type
array = np.zeros((3, 3))
tensor1 = torch.tensor(array) # array Create as import data tensor, Do not share id
tensor2 = torch.from_numpy(array) # be based on array establish tensor. share id
# 2、 Based on numerical formula
tensor3 = torch.zeros((3, 3)) # Do not read data , Create directly 0tensor
tensor4 = torch.zeros_like(tensor3) # Do not read data , Create directly with tensor3 etc. size Of 0tensor
tensor5 = torch.ones((3, 3)) # ditto
tensor6 = torch.ones_like(tensor5) # ditto
tensor7 = torch.full((3, 3), fill_value=4) # ditto
tensor8 = torch.full_like(tensor7, fill_value=5) # ditto
tensor9 = torch.linspace(start=1, end=10, steps=2) # Build equal 1 D tensor (start,end,Steps=)
tensor10 = torch.logspace(start=1, end=10, steps=3, base=2) # Build logarithm average 1 D tensor (start,end,Steps= Sequence length ,base= The base of a logarithmic function , Default 10)
tensor11 = torch.eye(n=3, m=4) # Create a two-dimensional unit diagonal matrix
# Based on probability formula
tensor12 = torch.randn((3, 3)) # Generate standard normal distribution (size= The shape of the tensor )
tensor13 = torch.randn_like(tensor12)
tensor14 = torch.rand((3, 3)) # Generated in [0,1) Uniform distribution of
tensor15 = torch.rand_like(tensor14)
tensor16 = torch.randint(low=1, high=10, size=(3, 3)) # Generated in [low,high) Uniform distribution of integers (size= The shape of the tensor )
tensor17 = torch.randint_like(tensor16, low=1, high=10)
tensor18 = torch.randperm(n=10) # Generate 0 To n-1 The random arrangement of (n= Tensor length )
tensor19 = torch.bernoulli(tensor1) # With input Is probability , Generate Bernoulli distribution (0-1 Distribution ,input It's a probability value )
边栏推荐
- Gear2021 monthly update - December
- A. Odd Selection【BruteForce】
- win32:堆破壞的dump文件分析
- A. Odd Selection【BruteForce】
- Ml (machine learning) softmax function to realize the classification of simple movie categories
- [combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
- Redis core technology and practice - learning notes (11): why not just string
- supervisor监控Gearman任务
- 2022-2028 global petroleum pipe joint industry research and trend analysis report
- Micro service component sentinel console call
猜你喜欢

Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time

How to deploy applications on kubernetes cluster

How to draw non overlapping bubble chart in MATLAB

Class exercises

2022-2028 global plasmid DNA cdmo industry research and trend analysis report

PHP MySQL inserts data
![网格图中递增路径的数目[dfs逆向路径+记忆dfs]](/img/57/ff494db248171253996dd6c9110715.png)
网格图中递增路径的数目[dfs逆向路径+记忆dfs]

Ml (machine learning) softmax function to realize the classification of simple movie categories
![[combinatorics] generating function (summation property)](/img/74/e6ef8ee69ed07d62df9f213c015f2c.jpg)
[combinatorics] generating function (summation property)

Nodejs (01) - introductory tutorial
随机推荐
Image 24 bit depth to 8 bit depth
Three gradient descent methods and code implementation
Postfix 技巧和故障排除命令
How to expand the capacity of golang slice slice
Ssl/bio of OpenSSL_ get_ fd
SSL / bio pour OpenSSL Get FD
(8) HS corner detection
Fedora 21 安装 LAMP 主机服务器
Fedora 21 installs lamp host server
Applet with multiple tabs and Swipers + paging of each tab
Computer graduation design PHP sports goods online sales system website
SDNUOJ1015
G1 garbage collector of garbage collector
[LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
Codeforces Round #803 (Div. 2) C. 3SUM Closure
A. Odd Selection【BruteForce】
Micro service component sentinel console call
On Data Mining
CTO and programmer were both sentenced for losing control of the crawler
English grammar_ Noun classification