当前位置:网站首页>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 )
边栏推荐
- Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
- Image 24 bit depth to 8 bit depth
- [combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
- SDNUOJ1015
- 分布式的任务分发框架-Gearman
- win32:堆破坏的dump文件分析
- [combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
- [LINUX]CentOS 7 安装MYSQL时报错“No package mysql-server available“No package zabbix-server-mysql availabl
- Change the single node of Postgres database into master-slave
- PHP MySQL Update
猜你喜欢

基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition

Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing

How to draw non overlapping bubble chart in MATLAB

Administrative division code acquisition

The vscode code is automatically modified to a compliance code when it is formatted and saved

How to install PHP on Ubuntu 20.04

PHP MySQL inserts multiple pieces of data

Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it

Computer graduation design PHP sports goods online sales system website

BFS - topology sort
随机推荐
[combinatorics] generating function (commutative property | derivative property | integral property)
webcodecs
Fedora 21 安装 LAMP 主机服务器
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
圖像24比特深度轉8比特深度
Niuke monthly race 31 minus integer
How to deploy applications on kubernetes cluster
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
Naoqi robot summary 27
小程序 多tab 多swiper + 每个tab分页
图像24位深度转8位深度
PHP MySQL where clause
2022-2028 global physiotherapy clinic industry research and trend analysis report
How to track the real-time trend of Bank of London
What kind of experience is it when the Institute earns 20000 yuan a month?
SDNUOJ1015
204. Count prime
Computer graduation design PHP campus address book telephone number inquiry system
How to expand the capacity of golang slice slice