Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.mint.squeeze

View Source On Gitee
mindspore.mint.squeeze(input, dim)[source]

Return the Tensor after deleting the dimension of size 1 in the specified dim.

If dim=(), it will remove all the dimensions of size 1. If dim is specified, it will remove the dimensions of size 1 in the given dim. For example, if the dimension is not specified dim=(), input shape is (A, 1, B, C, 1, D), then the shape of the output Tensor is (A, B, C, D). If the dimension is specified, the squeeze operation is only performed in the specified dimension. If input shape is (A, 1, B), when dim=0 or dim=2, the input tensor is not changed, while when dim=1, the input tensor shape is changed to (A, B).

Note

  • Please note that in dynamic graph mode, the output Tensor will share data with the input Tensor, and there is no Tensor data copy process.

  • The dimension index starts at 0 and must be in the range [-input.ndim, input.ndim].

  • In GE mode, only support remove dimensions of size 1 from the shape of input tensor.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – Used to calculate Squeeze. The shape of tensor is (x1,x2,...,xR).

  • dim (Union[int, tuple(int)]) – Specifies the dimension indexes of shape to be removed, which will remove all the dimensions of size 1 in the given dim parameter. If specified, it must be int32 or int64.

Returns

Tensor, the shape of tensor is (x1,x2,...,xS).

Raises
  • TypeError – If input is not a tensor.

  • TypeError – If dim is not an int, tuple.

  • TypeError – If dim is a tuple whose elements are not all int.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> input = Tensor(np.ones(shape=[3, 2, 1]), mindspore.float32)
>>> output = mint.squeeze(input, 2)
>>> print(output)
[[1. 1.]
 [1. 1.]
 [1. 1.]]