import torch
import numpy as np
tensor = torch.ones((3, 3))
print(tensor)
t_cat_0 = torch.cat([tensor, tensor], dim=0)
print(t_cat_0, t_cat_0.shape)
t_cat_1 = torch.cat([tensor, tensor], dim=1)
print(t_cat_1, t_cat_1.shape)
t_stack_2 = torch.stack([tensor, tensor, tensor], dim=2)
print(t_stack_2, t_stack_2.shape)
t_chunk_1_2 = torch.chunk(tensor, dim=1, chunks=2)
for i, t in enumerate(t_chunk_1_2):
print(i, t, t.shape)
t_split_1_2 = torch.split(tensor, 2, dim=1)
for i, t in enumerate(t_split_1_2):
print(i, t, t.shape)
t_split_1_2 = torch.split(tensor, [1, 2],
dim=1)
for i, t in enumerate(t_split_1_2):
print(i, t, t.shape)
tensor = torch.randint(0, 6, size=(3, 3))
t_select = torch.select(tensor, dim=0, index=1)
print(tensor, '\n', t_select)
mask = tensor.ge(5)
t_maks = torch.masked_select(tensor, mask)
print(t_maks)
t_reshape = torch.reshape(tensor, shape=(9, 1))
print(t_reshape)
t_transpose = torch.transpose(tensor, dim0=0, dim1=1)
print(t_transpose)
t_t = torch.t(tensor)
print(t_t)
tensor = torch.rand((1, 2, 3, 1))
print(tensor.shape)
t_squeeze = torch.squeeze(tensor)
print(t_squeeze.shape)
t_unsqueeze = torch.unsqueeze(tensor,dim=1)
print(tensor.shape)
print(t_unsqueeze.shape)
|