当前位置:网站首页>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 )
边栏推荐
- Image 24 bits de profondeur à 8 bits de profondeur
- Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
- Computer graduation design PHP makeup sales Beauty shopping mall
- Win32: analyse du fichier dump pour la défaillance du tas
- 毕业总结
- [combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
- supervisor监控Gearman任务
- PHP MySQL where clause
- Count the number of pixel values in the image
- Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
猜你喜欢
Micro service component sentinel console call
win32:堆破坏的dump文件分析
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
2022-2028 global scar care product industry research and trend analysis report
Valentine's day, send you a little red flower~
Sensor debugging process
Codeforces Round #803 (Div. 2) C. 3SUM Closure
Ml (machine learning) softmax function to realize the classification of simple movie categories
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
Win32: dump file analysis of heap corruption
随机推荐
SDNUOJ1015
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
Distributed task distribution framework gearman
Kotlin的協程:上下文
Win32: analyse du fichier dump pour la défaillance du tas
What kind of experience is it when the Institute earns 20000 yuan a month?
Three gradient descent methods and code implementation
How to expand the capacity of golang slice slice
Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
English grammar_ Adjective / adverb Level 3 - multiple expression
What London Silver Trading software supports multiple languages
[combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
[combinatorics] generating function (summation property)
Design limitations of structure type (struct)
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
Nodejs (01) - introductory tutorial
Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time
Redis on local access server