Usage of torch.squeeze () and torch.unsqueeze () in pytorch learning


The usage of squeeze is mainly to compress or decompress the dimensions of the data.

Look firsttorch.squeeze() This function mainly compresses the dimensions of the data and removes the dimension with a dimension of 1, such as a row or a column. One row and three columns (1, 3) of the number removes the first dimension with a dimension of one. Becomes line (3). Squeeze (a) is to delete all the dimensions of 1 in a. Dimensions other than 1 have no effect. a.squeeze (N) is to remove the dimension specified in a as one. Another form is b = torch.squeeze (a, N) a remove the specified dimension as a dimension.

Look againtorch.unsqueeze()This function is mainly to expand the data dimension. Add a dimension of one dimension to the specified position. For example, there are three rows of data (3). Adding one dimension to the position of 0 becomes one row and three columns (1, 3). a.squeeze (N) is to add a dimension with dimension 1 to the specified position N in a. Another form is b = torch.squeeze (a, N) a is a specified position N in a plus a dimension with a dimension of 1


Look at Liezi below:





Reference materials:

  1. Pytorch common function analysis (1)
  2. numpy.squeeze

Intelligent Recommendation

pytorch grammar daily torch.squeeze () and torch.unsqueeze ()

1.torch.squeeze() torch.squeeze(input, dim=None, out=None) The parameters are: Input (Tensor) -Enter Tensor DIM (int, Optional) -If given, input will only squeeze in a given dimension out (tensor, opt...

Torch.unsqueeze () and torch.squeeze ()

Torch.unsqueeze () and torch.squeeze () 1.torch.unsqueeze() prototype: Role: Extended dimensions, returns a new sheet, insert the dimension 1 for the input. parameter: tensor (Tensor) - Enter the amou...

Torch.squeeze () with torch.unsqueeze ()

1.Torch.squeeze () horizontal contrast to Torch.unsqueeze () on one-dimensional array in conclusion: Torch.squeeze () Reduce a dimension before the specified dimension Torch.unsqueeze () adds a dimens...

torch.squeeze and torch.unsqueeze

torch.squeeze Function: Remove the dimension of size as 1. When the dimension is greater than or equal to 2, squeeze () has no effect. torch.unsqueeze Function: Contrary to Squeeeze (), it is used to ...

More Recommendation

The usage of pytorch learning records-torch.max and torch.unsqueeze ()

1. Torch.max (x, 0): Returns the maximum value and corresponding index in a column. 2. TORCH.MAX (x, 1): Return to the maximum value and corresponding index in one line. 3. Torch.unSqueeze (input, DIM...

Master the use of torch.squeeze() and torch.unsqueeze()

torch.squeeze() This function mainly compresses the dimensions of the data and removes the dimension with dimension 1 by default. By default, all dimensions of 1 in a are deleted. You can also specify...

torch.gather, torch.squeeze and torch.unsqueeze

torch.gather binding torch.squeeze and extracts each row torch.unsqueeze achieve the specified element (expandable high dimensional) Output:...

The difference between torch.squeeze() and torch.unsqueeze()

torch.squeeze() mainly compresses the dimensions of the data, removing the dimension with a dimension of 1 (the first one, that is, the outermost one), such as one row or one column, one row and three...

torch.unsqueeze and torch.squeeze() in detail

1. torch.unsqueeze detailed torch.unsqueeze(input, dim, out=None) effect: Extended dimension Return a new tensor, inserting dimension 1 into the given position of the input note: The returned tensor s...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top