shape_refine
Description
Returns the shape list with the dimension sized 1 removed if the axis to be reduced is None; returns a tuple formatted as (shape, axis) that consists of the shape of dimensions valued other than 1 and the list of sorted axes to be reduced otherwise.
Prototype
def shape_refine(shape, reduce_axis=None, keep_dims=True):
Parameters
Parameter |
Description |
|---|---|
shape |
Input shape. |
reduce_axis |
An int or a list or tuple of ints, for the axis or axes to be reduced. |
keep_dims |
A bool. True indicates that the dimensions are retained; False indicates that the dimensions are reduced. Defaults to True. |
Returns
- If only the shape argument is passed, only the shape result is output.
- If both shape and reduce_axis arguments are passed, a tuple formatted as (shape, axis) is output.
Restrictions
Refinement is not supported if shape of the axis to reduce is 1.
Examples
Example 1:
from tbe.common.utils import shape_util shape_util.shape_refine((32, 64, 64, 1), reduce_axis=None)
Return: (32, 64, 64).
Example 2
from tbe.common.utils import shape_util shape_util.shape_refine((32, 64, 64, 1), reduce_axis=[-2, -1], keep_dims=False)
Return ([32, 64, 64], [2]).
Parent topic: Shape-related Tools