Now the parameters 0 Corresponding 3 The block becomes 2 block Parameters 1 Corresponding 2 The line has changed.Char * s = "hello" 等价于 char str = "hello" 내가 이해하기로는 PyTorch에서 contiguous는 아마도 tensor에서 바로 옆에 있는 요소가 실제로 메모리상에서 서로 인접해있느냐를 의미한다. 3 That's ok Parameters 2 Corresponding 5 The column becomes 2 Column Change six :0 And 1 In exchange for ,0 And 2 In exchange for b = x.permute( 1, 2, 0) # Swap blocks and rows and columns print(b) Now the parameters 0 Corresponding 3 The block becomes 5 block Parameters 1 Corresponding 2 The line has changed. Now the parameters 0 Corresponding 3 Block pass permute Has become 5 block Parameters 2 Corresponding 5 The column has become 3 Column Change five :0 And 1 In exchange for ,1 And 2 In exchange for b = x.permute( 2, 0, 1) # Swap blocks and rows and columns print(b) Now it becomes 2 block * 3 That's ok * 5 Column ( For the initial 3 block * 2 That's ok *5 Column ) Change 4 :0 And 2 In exchange for b = x.permute( 2, 1, 0) # Swap blocks and columns print(b) This change happens to be 0 And 1 The exchange of positions, Cause the parameters to be adjusted Parameters 1 Corresponding 2 Line into 3 That's ok The parameter 0 The corresponding value 3 Block becomes 2 block The comparison between the two shows that the number of blocks and the number of rows in each block have changed Without changing every piece ( namely ) Under the premise of, Swap the rows and columns of each block ( The transpose of a two-dimensional matrix ) Change three :0 And 1 In exchange for b = x.permute( 1, 0, 2) # Swap blocks and rows print(b) It is found that the matrix does not change at this time, It's still arranged in the same way as before Change 2 :1 And 2 In exchange for b = x.permute( 0, 2, 1) # The rows and columns of each block are exchanged, That is, each piece does transpose behavior print(b)
#Permute by row torch code#
It's kind of like x,y,z To distinguish three coordinate dimensions, It's man-made The three-dimensional situation is explained to you directly with the following code Three dimensional situation Change one : Do not change any parameters b = x.permute( 0, 1, 2) # Don't change dimensions print(b) permute(0,1) There is no change here, Same dimension as before If written permute(1,0) What you get is the transpose of the matrix If 3D is permute(0,1,2) 0 Represents a total of several dimensions : In this case 0 Corresponding 3 Block matrix 1 Represents how many lines there are in each block : In this case 1 Corresponding to each piece, there are 2 That's ok 2 Represents how many columns there are in each block : In this case 2 Corresponding to each piece, there are 5 Column So it is 3 block 2 That's ok 5 Three dimensional matrix of columns these 0,1,2 There is no practical significance, Nor is it a numerical value, Just to identify the difference. Of course, the matrix must be at least two dimensions to use permute If it is two-dimensional ,dims They are 0 and 1 It can be written. That is to say 0 dimension, The first 1 Wei and so on It can also be understood as, The first 0 block, The first 1 And so on. Permute(dims) Parameters dims Substitute the dimension of the matrix into, Generally, the default is from 0 Start. Next, let's briefly introduce permute() function I'll simply use 3 block 3*3 Figure example of laziness Then it's piled up, which is what we know as a three-dimensional matrix Such as (3,2,5), Express 3 block 2*5 Array of So let's follow the block, That's ok, Columns are easier to understand General handle (3,2,5) Interpreted as 3 dimension 2 That's ok 5 It's easy to get confused here Here, in order to prevent the coincidence of the same dimension value ( For example, a three-dimensional array (3,3,3) perhaps (2,4,4) etc.
![permute by row torch permute by row torch](https://d2vlcm61l7u1fs.cloudfront.net/media/ad5/ad56bbc2-0c7f-4281-b962-86678cb66761/phpCFdhjE.png)
Print(x.size()) # Check the dimension of the array Copy code X = torch.linspace( 1, 30, steps= 30).view( 3, 2, 5) # Set a 3D array print(x) I'll explain it in combination with code and picturesįirst, create a small instance of a three-dimensional array import torch This paper only discusses the two-dimensional and three-dimensional permute usageĬurrent Attention One of the learning permute Functions don't make me understand This article has participated in 「 New people's creation ceremony 」 Activities, Start the road of nuggets creation together Preface This article has participated in 「 New people's creation ceremony 」 Activities, Start the road of nuggets creation together.