当前位置:网站首页>Torch. correlation function
Torch. correlation function
2022-07-27 00:24:00 【Acowardintheworld】
torch.nonzero()
Docstring:nonzero(input, *, out=None, as_tuple=False) -> LongTensor or tuple of LongTensors
The parameters involved are mainly input and as_tuple, In fact, it is whether to return to a tuple , Default is not tuple .
Just look at the following example .
"""as_tuple=False By default """
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]))
tensor([[ 0],
[ 1],
[ 2],
[ 4]]) # Returns yes or no 0 Index of elements , And is the matrix of the index ,shape= ( Non zero elements ,1)
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.5, 0.0],
[0.0, 0.4, 0.0, 0.0],
[0.0, 0.0, 1.2, 0.0],
[0.0, 0.0, 0.0,-0.4]]))
tensor([[ 0, 0],
[ 0, 2],
[ 1, 1],
[ 2, 2],
[ 3, 3]]) # Returns the index of non-zero elements in the matrix , Each element contains a row and column index ,shape= ( Non zero elements ,2)
"""as_tuple=True By default """
>>> torch.nonzero(torch.tensor(5), as_tuple=True)
(tensor([0]),) # Return is also a tensor index , Just put it in a tuple
>>> torch.nonzero(torch.tensor([1, 1, 1, 0, 1]), as_tuple=True)
(tensor([0, 1, 2, 4]),) # No difference , But to extract an element in the list , Must have two index values , They are a whole , For example, to extract 1,[0][1]
>>> torch.nonzero(torch.tensor([[0.6, 0.0, 0.5, 0.0],
[0.0, 0.4, 0.0, 0.0],
[0.0, 0.0, 1.2, 0.0],
[0.0, 0.0, 0.0,-0.4]]), as_tuple=True)
# What we return are two list tensors constitute A tuple of , Tuples [0] Is the row position of non-zero elements in turn , Tuples [1] Is the column position of non-zero elements in turn ,
(tensor([0, 0, 1, 2, 3]), tensor([0, 2, 1, 2, 3]))
summary : Actually as_tuple=True Returning tuples is useless , If you need the row position or column position of non-zero elements, you can set it , In fact, it is as_tuple=False The first and second columns returned .
X.permute(dims)
take tensor Dimensional transposition of
https://zhuanlan.zhihu.com/p/76583143
torch.flatten(t,start_dim= Start dimension ,end_dim= End dimension )
Reduce some dimensions of the matrix , But elements are not lost
t = torch.arange(120,).reshape(2,3,4,5)
t
t.shape
torch.flatten(t,start_dim=1,end_dim=-2)
torch.flatten(t,start_dim=1,end_dim=-2).shape
边栏推荐
猜你喜欢

Mysql database complex operations: Database Constraints, query / connect table operations

Tencent cloud lightweight application server purchase method steps!

爬虫解析网页的find方法

放图仓库-2(函数图像)

1、 Kubernetes basic concept + environment installation (build cross server public network environment)

Opencv camera calibration and distortion correction

Double. isNaN(double var)

4. Talk about the famous Zhang Zhengyou calibration method

爬虫解析网页的 对象.元素名方法

Share a regular expression
随机推荐
Fourier analysis (basic introduction)
Several search terms
机器人学台大林教授课程笔记
蒙着头配置deeplabcut 1
Find method of web page parsing by crawler
Practice of data storage scheme in distributed system
Analysis of encoding and decoding of encode() and decode(), common encoding and why encode and decode are needed
Complete review of parsing web pages
Chapter 1 develop the first restful application
2022_ SummerBlog_ 008
RecBole使用1
Blue Bridge Cup brush question notes (word analysis)
Alexnet (pytoch Implementation)
Method of setting QQ to blank ID
Downloading and processing of sentinel-2
Course notes of Professor Dalin of robotics platform
CSDN文章语法规则
Mysql8 installation
About no module named'django.db.backends.mysql'
Codeforces d.constructing the array (priority queue)