torch.squeeze()、torch.unsqueeze()、torch.randn()、torch.nn.Linear()、torch.Tensor.expand_as、numpy.mean(a, axis, dtype, out,keepdims )、numpy.std(a, axis=None, dtype=None, out=None, ddof=0, keepdims)
1、torch.squeeze()
torch.squeeze(input, dim=None, out=None)
- input (Tensor) ,input为输入的tensor
- dim (int, optional) ,dimension,只对输入tensor的该维度进行压缩
- out (Tensor, optional),out输出的也是tensor
torch.squeeze()可以理解为对张量进行降维操作,若某一维度的维度值为1,则去除该维度该维度,若输入X的维度为(A×1×B×C×1×D) ,执行 torch.squeeze(X),输出tensor的形状为(A×B×C×D);
再如,input=(A×1×B) , squeeze(input, 0),0表示第一维度,第一维度值为A,不是1,所以不变; 执行squeeze(input, 1),1表示第二维度,第二维度值为1,则去除,因此 input=(A×B) 。
下面举例说明
#先注明torch.zeros()
#torch.zeros(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False)
>>> torch.zeros(2, 3)
tensor([[ 0., 0., 0.],
[ 0., 0., 0.]])
>>> torch.zeros(5)
tensor([ 0., 0., 0., 0., 0.])
>>> x = torch.zeros(2, 1, 2, 1, 2)
>>> x.size()
#torch.Size 返回张量形状
torch.Size([2, 1, 2, 1, 2])
>>> y