Removes dimensions of size 1 from the shape of a tensor. Given a tensor `input`, this operation returns a tensor of the same type with all dimensions of size 1 removed. If you don't want to remove all size 1 dimensions, you can remove specific size 1 dimensions by specifying `axis`. For
(input, axis=None, name=None)
| 3656 | @tf_export("squeeze", v1=[]) |
| 3657 | @dispatch.add_dispatch_support |
| 3658 | def squeeze_v2(input, axis=None, name=None): |
| 3659 | """Removes dimensions of size 1 from the shape of a tensor. |
| 3660 | |
| 3661 | Given a tensor `input`, this operation returns a tensor of the same type with |
| 3662 | all dimensions of size 1 removed. If you don't want to remove all size 1 |
| 3663 | dimensions, you can remove specific size 1 dimensions by specifying |
| 3664 | `axis`. |
| 3665 | |
| 3666 | For example: |
| 3667 | |
| 3668 | ```python |
| 3669 | # 't' is a tensor of shape [1, 2, 1, 3, 1, 1] |
| 3670 | tf.shape(tf.squeeze(t)) # [2, 3] |
| 3671 | ``` |
| 3672 | |
| 3673 | Or, to remove specific size 1 dimensions: |
| 3674 | |
| 3675 | ```python |
| 3676 | # 't' is a tensor of shape [1, 2, 1, 3, 1, 1] |
| 3677 | tf.shape(tf.squeeze(t, [2, 4])) # [1, 2, 3, 1] |
| 3678 | ``` |
| 3679 | |
| 3680 | Unlike the older op `tf.compat.v1.squeeze`, this op does not accept a |
| 3681 | deprecated `squeeze_dims` argument. |
| 3682 | |
| 3683 | Note: if `input` is a `tf.RaggedTensor`, then this operation takes `O(N)` |
| 3684 | time, where `N` is the number of elements in the squeezed dimensions. |
| 3685 | |
| 3686 | Args: |
| 3687 | input: A `Tensor`. The `input` to squeeze. |
| 3688 | axis: An optional list of `ints`. Defaults to `[]`. If specified, only |
| 3689 | squeezes the dimensions listed. The dimension index starts at 0. It is an |
| 3690 | error to squeeze a dimension that is not 1. Must be in the range |
| 3691 | `[-rank(input), rank(input))`. Must be specified if `input` is a |
| 3692 | `RaggedTensor`. |
| 3693 | name: A name for the operation (optional). |
| 3694 | |
| 3695 | Returns: |
| 3696 | A `Tensor`. Has the same type as `input`. |
| 3697 | Contains the same data as `input`, but has one or more dimensions of |
| 3698 | size 1 removed. |
| 3699 | |
| 3700 | Raises: |
| 3701 | ValueError: The input cannot be converted to a tensor, or the specified |
| 3702 | axis cannot be squeezed. |
| 3703 | """ |
| 3704 | # pylint: disable=redefined-builtin |
| 3705 | return squeeze(input, axis, name) |
| 3706 | |
| 3707 | |
| 3708 | @tf_export(v1=["where"]) |