1. torch.flatten(input,start_dim=0,end_dim=-1)
2.torch.reshape(input,shape)
3.torch.squeeze(input, dim=None, out=None)
4.torch.unsqueeze(input, dim)
5.torch.cat(tensors, dim=0, out=None)
6.view(*shape)
7.torch.transpose(input, dim0, dim1)
下面记录一下reshape和view函数的区别:
- reshape():Returns a tensor with the same data and number of elements as
input
, but with the specified shape. When possible, the returned tensor will be a view ofinput
. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.Seetorch.Tensor.view()