Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

torch.stack example

>>> a = torch.randn([2, 3, 4])
>>> b = torch.randn([2, 3, 4])
>>> torch.stack([a, b]).shape
torch.Size([2, 2, 3, 4])
Comment

torch.stack example

a.size()  # 2, 3, 4
b.size()  # 2, 3
b = torch.unsqueeze(b, dim=2)  # 2, 3, 1
# torch.unsqueeze(b, dim=-1) does the same thing

torch.stack([a, b], dim=2)  # 2, 3, 5
Comment

torch.stack example

>>> import torch
>>> a = torch.randn([2, 3, 4])
>>> b = torch.randn([2, 3])
>>> b = b.unsqueeze(dim=2)
>>> b.shape
torch.Size([2, 3, 1])
>>> torch.cat([a, b], dim=2).shape
torch.Size([2, 3, 5])
Comment

torch.stack

> torch.stack(
    (t1,t2,t3)
    ,dim=0
)
tensor([[1, 1, 1],
        [2, 2, 2],
        [3, 3, 3]])
Comment

PREVIOUS NEXT
Code Example
Python :: how to get a character from a string in python 
Python :: convert string to integer in python 
Python :: how to save plot in matplotlib 
Python :: numpy cumsum 
Python :: transpose matrice numpy 
Python :: python repr vs str 
Python :: update python 2 to 3 
Python :: index of and last index of in python 
Python :: Adding a new column in pandas dataframe from another dataframe with different index 
Python :: python set split limit 
Python :: return function in python 
Python :: iterrows pandas 
Python :: serialize list to json python 
Python :: for in loop python 
Python :: create tuples in pandas 
Python :: django raw without sql injection 
Python :: channels_redis 
Python :: pivot index 
Python :: pyqt matplotlib 
Python :: print python reverse list 
Python :: python loop to a tuple 
Python :: find index of value in list python 
Python :: opening a file in python 
Python :: python sleep command 
Python :: python split string by specific word 
Python :: run python module from command line 
Python :: loop through files in a directory python 
Python :: upload file setup django url 
Python :: python tkinter focus on entry 
Python :: how to implement dfa in python 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =