当前位置:网站首页>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 )
边栏推荐
- [combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
- The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
- AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
- [LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
- [Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
- [Godot] add menu button
- Class exercises
- supervisor监控Gearman任务
- [combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
- 2022-2028 global marking ink industry research and trend analysis report
猜你喜欢

2022-2028 global petroleum pipe joint industry research and trend analysis report

G1 garbage collector of garbage collector

Mysql45 lecture learning notes (II)

How to deploy applications on kubernetes cluster

Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up

2022-2028 global scar care product industry research and trend analysis report
![Golang string (string) and byte array ([]byte) are converted to each other](/img/41/20f445ef9de4adf2a2aa97828cb67f.jpg)
Golang string (string) and byte array ([]byte) are converted to each other

Prototype inheritance..

AcWing 271. 杨老师的照相排列【多维DP】

English grammar_ Adjective / adverb Level 3 - multiple expression
随机推荐
Setinterval CPU intensive- Is setInterval CPU intensive?
分布式的任务分发框架-Gearman
A. Berland Poker &1000【简单数学思维】
[combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
[combinatorics] generating function (positive integer splitting | basic model of positive integer splitting | disordered splitting with restrictions)
Gear2021 monthly update - December
On Data Mining
PHP MySQL reads data
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
Enterprise custom form engine solution (12) -- form rule engine 2
Win32: analyse du fichier dump pour la défaillance du tas
Computer graduation design PHP makeup sales Beauty shopping mall
[combinatorics] generating function (summation property)
Administrative division code acquisition
199. Right view of binary tree - breadth search
Mysql45 lecture learning notes (II)
Niuke monthly race 31 minus integer
PHP MySQL inserts multiple pieces of data
English语法_名词 - 分类
Module 9 operation